HOME> 世界杯颁奖仪式> QQ批量加好友工具,QQ一键批量添加好友,python最新模块功能

QQ批量加好友工具,QQ一键批量添加好友,python最新模块功能

下载地址:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:1211 这段代码演示了如何使用Selenium自动化工具模拟QQ网页版的登录和添加好友操作。...

下载地址:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:1211

这段代码演示了如何使用Selenium自动化工具模拟QQ网页版的登录和添加好友操作。代码包含登录验证、好友搜索、验证信息填写等完整流程,并加入了随机延迟和异常处理机制。请注意这仅用于技术学习,实际批量添加好友可能违反服务条款

代码语言:txt复制

import time

import random

from selenium import webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.chrome.service import Service

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.common.exceptions import TimeoutException, NoSuchElementException

class QQFriendAdder:

def __init__(self, qq_number, password, chrome_driver_path):

self.qq_number = qq_number

self.password = password

self.driver_path = chrome_driver_path

self.driver = None

self.wait_timeout = 30

def init_driver(self):

options = webdriver.ChromeOptions()

options.add_argument("--disable-notifications")

options.add_argument("--disable-infobars")

options.add_argument("--disable-extensions")

options.add_argument("--disable-gpu")

options.add_argument("--no-sandbox")

service = Service(executable_path=self.driver_path)

self.driver = webdriver.Chrome(service=service, options=options)

self.driver.maximize_window()

def login_qq(self):

self.driver.get("https://qzone.qq.com/")

time.sleep(3)

try:

# 切换到iframe

iframe = self.driver.find_element(By.ID, "login_frame")

self.driver.switch_to.frame(iframe)

# 点击账号密码登录

switch_btn = WebDriverWait(self.driver, self.wait_timeout).until(

EC.presence_of_element_located((By.ID, "switcher_plogin"))

)

switch_btn.click()

# 输入QQ号和密码

qq_input = WebDriverWait(self.driver, self.wait_timeout).until(

EC.presence_of_element_located((By.ID, "u"))

)

qq_input.clear()

qq_input.send_keys(self.qq_number)

pwd_input = self.driver.find_element(By.ID, "p")

pwd_input.clear()

pwd_input.send_keys(self.password)

# 点击登录按钮

login_btn = self.driver.find_element(By.ID, "login_button")

login_btn.click()

# 等待登录成功

WebDriverWait(self.driver, self.wait_timeout).until(

EC.presence_of_element_located((By.ID, "QM_OwnerInfo_Icon"))

)

print("登录成功")

return True

except Exception as e:

print(f"登录失败: {str(e)}")

return False

def add_friends(self, qq_numbers, note="你好,交个朋友"):

if not isinstance(qq_numbers, list):

qq_numbers = [qq_numbers]

added_count = 0

self.driver.get("https://qun.qq.com/member.html")

time.sleep(5)

try:

# 点击添加好友按钮

add_btn = WebDriverWait(self.driver, self.wait_timeout).until(

EC.presence_of_element_located((By.XPATH, "//a[contains(text(),'添加好友')]"))

)

add_btn.click()

time.sleep(2)

for qq in qq_numbers:

try:

# 输入QQ号

search_input = WebDriverWait(self.driver, self.wait_timeout).until(

EC.presence_of_element_located((By.XPATH, "//input[@placeholder='输入QQ号/昵称']"))

)

search_input.clear()

search_input.send_keys(str(qq))

search_input.send_keys(Keys.RETURN)

time.sleep(3)

# 点击添加按钮

add_friend_btn = WebDriverWait(self.driver, self.wait_timeout).until(

EC.presence_of_element_located((By.XPATH, "//a[contains(text(),'加好友')]"))

)

add_friend_btn.click()

time.sleep(2)

# 填写验证信息

note_input = WebDriverWait(self.driver, self.wait_timeout).until(

EC.presence_of_element_located((By.XPATH, "//textarea[@name='verification']"))

)

note_input.clear()

note_input.send_keys(note)

time.sleep(1)

# 点击确定按钮

confirm_btn = self.driver.find_element(By.XPATH, "//a[contains(text(),'确定')]")

confirm_btn.click()

time.sleep(3)

# 返回继续添加

continue_btn = WebDriverWait(self.driver, self.wait_timeout).until(

EC.presence_of_element_located((By.XPATH, "//a[contains(text(),'继续添加')]"))

)

continue_btn.click()

time.sleep(2)

added_count += 1

print(f"成功添加QQ: {qq}")

# 随机延迟防止频繁操作

time.sleep(random.uniform(2, 5))

except Exception as e:

print(f"添加QQ {qq} 失败: {str(e)}")

continue

print(f"添加完成,共成功添加 {added_count} 个好友")

return added_count

except Exception as e:

print(f"添加好友过程中出错: {str(e)}")

return 0

def close(self):

if self.driver:

self.driver.quit()

if __name__ == "__main__":

# 使用示例 - 请替换为您的实际信息

qq_number = "123456789" # 您的QQ号

password = "your_password" # 您的QQ密码

chrome_driver_path = "chromedriver.exe" # ChromeDriver路径

# 要添加的QQ号列表

friends_to_add = [

"987654321",

"123123123",

"456456456"

]

adder = QQFriendAdder(qq_number, password, chrome_driver_path)

try:

adder.init_driver()

if adder.login_qq():

adder.add_friends(friends_to_add, "你好,交个朋友")

finally:

adder.close()


珠海按摩揼骨|10大珠海SPA按摩店推介!正宗泰式按摩/小顏整骨/過夜套票 iOS签名包更新避坑指南:三步告别"掉签"危机