pyautotui实现自动发送微信消息
代码
import pyautogui,pyperclip,time width, height = pyautogui.size() x, y = pyautogui.position() pyautogui.PAUSE=1 # 维护区 name = 'me' # 发送人 text = 'test_pyautogui' # 发送消息 # 打开微信 def open_wechat(): pyautogui.hotkey('ctrl', 'alt', 'w') time.sleep(1) # 查找发送人 def chat_who(name): pyautogui.hotkey("ctrl","f") pyperclip.copy(name) pyautogui.hotkey('ctrl', 'v') time.sleep(1) pyautogui.hotkey('Enter') time.sleep(1) # 获取要发送的图片 def get_imgs(): pyautogui.click(370,1175,clicks=1,duration=0.5) #点击 pyautogui.write(r'"ele1668.png" "ele186214.png"') pyautogui.press('enter', presses=1) # 获取要发送的文本 def get_text(text): pyperclip.copy(str(text)) pyautogui.hotkey('ctrl', 'v') # 点击发送 def sent_msg(): pyautogui.hotkey('ctrl', 'Enter') # main函数 def main(name, text): open_wechat() chat_who(name) get_imgs() sent_msg() get_text(text) sent_msg() main(name,text) # 执行 pyautogui.hotkey('ctrl', 'alt', 'w') # 隐藏微信
参考文章:
基础教程:https://zhuanlan.zhihu.com/p/302592540
基础教程+实例:https://zhuanlan.zhihu.com/p/350449485
发送文件:https://www.cnblogs.com/suanmiaoup/p/12389412.html