200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > Python实现微信批量发送消息

Python实现微信批量发送消息

时间:2021-11-29 15:31:44

相关推荐

Python实现微信批量发送消息

注意需要先打开微信

import win32clipboard as wimport win32conimport win32apiimport win32guiimport time# 读取一个docx文件,并存储到列表中。12月20日def read_docx(path):doc = docx.Document(path)paras_temp = [] # 用来存储段落for p in doc.paragraphs:p1 = p.text.replace(" ", "") # 去除空格paras_temp.append(p1)print(path + "文件读取成功!\n")return paras_temp# 把文字放入剪贴板def setText(aString):w.OpenClipboard()w.EmptyClipboard()w.SetClipboardData(win32con.CF_UNICODETEXT,aString)w.CloseClipboard()# 模拟ctrl+Vdef ctrlV():win32api.keybd_event(17,0,0,0) #ctrlwin32api.keybd_event(86,0,0,0) #Vwin32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0)#释放按键win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0)#模拟alt+sdef altS():win32api.keybd_event(18,0,0,0)win32api.keybd_event(83,0,0,0)win32api.keybd_event(83,0,win32con.KEYEVENTF_KEYUP,0)win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0)# 模拟enterdef enter():win32api.keybd_event(13,0,0,0)win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)# 模拟单击def click():win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)# 移动鼠标的位置def movePos(x,y):win32api.SetCursorPos((x,y))if __name__=="__main__":# 获取鼠标当前位置# hwnd=win32gui.FindWindow("MozillaWindowClass",None)hwnd = win32gui.FindWindow("WeChatMainWndForPC", None)win32gui.ShowWindow(hwnd,win32con.SW_SHOW)win32gui.MoveWindow(hwnd,0,0,1000,700,True)time.sleep(0.01)# 1.移动鼠标到通讯录位置,单击打开通讯录movePos(28,147)click()# 2.移动鼠标到搜索框,单击,输入要搜索的名字movePos(148,35)click()setText('Legend') # 好友ctrlV()time.sleep(1) # 停1秒,给微信一个反应的时间enter()time.sleep(1)# 3.复制要发送的消息,发送、Legendcount = 0# 发送一句话N次while (count < 2):setText('太强了')ctrlV()altS()time.sleep(0.5)count = count + 1

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。