from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver = webdriver.Chrome() driver.implicitly_wait(5) chrome_option = webdriver.ChromeOptions() chrome_option.add_argument('--proxy--server=127.0.0.1:8080')#使用代理IP,告诉服务器这是人为操作 driver.get('https://wx2.qq.com/')#打开网页版微信 time.sleep(10) search = driver.find_element_by_xpath('//*[@id="search_bar"]/input')#查找搜索框 search.click()#点击搜索框 time.sleep(1) name = input("请输入微信好友:") search.send_keys(name)#输入微信好友搜索 time.sleep(8)#等待加载好友 search.send_keys(Keys.ENTER)#默认点击第一个好友 #中秋快乐所在的点位 overNumber = [3,9,15,20,23,27,31,32,35,37,38,39,40,41,42,43,44,45,46,47,48,49,51,53,55,56,58,59,60,61,62,63,64,65,67,68,69,71,75,78,80,82,83,78,89,92,93,96,99,104,111,116,134,137,144,146,149,154,155,158,161,164,165,169,170,172,173,174,176,178,181,182,183,185,186,188,189,190,191,192,194,195,196,197,198,199,202,206,209,213,214,215,218,220,222,224,226,227,230,231,234,235,238,240,242,247,249,250] global i i = 1 def start(): driver.find_element_by_xpath('//*[@id="tool_bar"]/a[1]').click()#点击表情包 choose() def choose():#根据循环的数字判断点击的表情包 global i for i in range(1,265,1): print ("正在点击%s"%i) if i in overNumber: face() else: rose() driver.find_element_by_xpath('//*[@id="chatArea"]/div[3]/div[3]/a').click()#点击"发送"按钮 print ("执行完毕!!!") def face():#点击表情包”礼物“ driver.find_element_by_xpath('//*[@id="mmpop_emoji_panel"]/div/div/div[1]/div[1]/div/a[78]').click() def rose():#点击表情包”玫瑰“ driver.find_element_by_xpath('//*[@id="mmpop_emoji_panel"]/div/div/div[1]/div[1]/div/a[64]').click()
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver = webdriver.Chrome() driver.implicitly_wait(5) chrome_option = webdriver.ChromeOptions() chrome_option.add_argument('--proxy--server=127.0.0.1:8080')#使用代理IP,告诉服务器这是人为操作 driver.get('https://wx2.qq.com/')#打开网页版微信 time.sleep(10) search = driver.find_element_by_xpath('//*[@id="search_bar"]/input')#查找搜索框 search.click()#点击搜索框 time.sleep(1) name = input("请输入微信好友:") search.send_keys(name)#输入微信好友搜索 time.sleep(8)#等待加载好友 search.send_keys(Keys.ENTER)#默认点击第一个好友 #"中秋"所占的位置 zhOngQiuNumber= [6,18,30,39,40,41,42,43,44,45,51,54,57,63,66,69,75,76,77,78,79,80,81,90,102,114,126,148,149,152,159,164,170,172,175,176,178,182,183,184,185,187,188,189,195,196,199,200,201,207,208,209,212,218,220,222,223,225,232,234,234,238,244,245,251,256,264] #"快乐"所占的位置 kuaiLeNumber = [267,272,279,284,291,296,302,303,306,307,308,309,340,314,315,316,320,322,326,327,328,332,334,337,339,340,342,343,344,345,346,347,348,351,356,363,367,369,375,378,382,383,384,405,415,416,424,425,426,436,439,448,451,460,461,462,463,464,465,466,475,486,487,488,497,499,501,508,511,514,519,523,527,528,534,535,547] global i#定义全局变量 i = 1 global k k = 1 def start(): driver.find_element_by_xpath('//*[@id="tool_bar"]/a[1]').click()#点击表情包 def zhongQiu():#"中秋"模块 global i for i in range(1,277,1): print ("正在为中秋点击%s"%i) if i in zhongQiuNumber: face() else: rose() driver.find_element_by_xpath('//*[@id="chatArea"]/div[3]/div[3]/a').click()#点击"发送"按钮
def kuaiLe():#"快乐"模块 global k for k in range(265,565,1): print ("正在为快乐点击%s"%k) if k in kuaiLeNumber: face() else: rose() word() def face():#点击表情包”礼物“ driver.find_element_by_xpath('//*[@id="mmpop_emoji_panel"]/div/div/div[1]/div[1]/div/a[78]').click() def rose():#点击表情包”玫瑰“ driver.find_element_by_xpath('//*[@id="mmpop_emoji_panel"]/div/div/div[1]/div[1]/div/a[64]').click() def word():#发送文字祝福语 driver.find_element_by_xpath('//*[@id="editArea"]').send_keys("友祝你中秋快乐,阖家欢乐!")#输入祝福语 driver.find_element_by_xpath('//*[@id="chatArea"]/div[3]/div[3]/a').click()#点击发送 print ("已经为你送出祝福")
if __name__ == '__main__': start() zhongQiu()#开始执行"中秋"模块 start() kuaiLe()#开始执行"快乐"模块