1、由于电脑登录微信需手机进行验证,此处略过自动打开微信。
2、安装所需支撑文件:
pip install wxChat
pip install pyautogui
3、修改wxauto.py
由于版本原因,此片需修改wxauto.py,在引入处按住ctrl,点wxchart,就可打开文件,找到class Wechart:
class WeChat: def __init__(self): self.UiaAPI = uia.WindowControl(ClassName='WeChatMainWndForPC') self.SessionList = self.UiaAPI.ListControl(Name='会话') # self.EditMsg = self.UiaAPI.EditControl(Name='输入') self.SearchBox = self.UiaAPI.EditControl(Name='搜索') self.MsgList = self.UiaAPI.ListControl(Name='消息') self.SessionItemList = [] def control(self,ctname): self.EditMsg=self.UiaAPI.EditControl(name=ctname) 备注掉self.EditMsg = self.UiaAPI.EditControl(Name='输入')。加上 def control(self,ctname): 4、测试发送信息: import time from wxauto import WeChat import pyautogui,sys print("输入发送人的备注:") keyword="XXX" --微信备注联系人 print("请输入推迟打开微信时间(S):") t_delay1=1 print("请输入推迟发送时间(s):") t_delay2=1 print("请选择发送消息还是文件:1.消息 2 文件,输入1或2.") chartype=2 if chartype==1: print("请输入发送的消息:") chat_message="hello word!" elif chartype==2: print("请输入文件的路径:") chat_file_path=r"E:\XXXXX" --指定文件位置time.sleep(t_delay1)
# pyautogui.click(35,447) # pyautogui.doubleClick(35,447)
wx=WeChat() wx.GetSessionList()
who=wx.Search(keyword) wx.control(who) time.sleep(t_delay2)
if chartype==1: wx.SendMsg(chat_message) elif chartype==2: wx.SendFiles(chat_file_path) 5 测试 在win10,python3.11下测试成功 标签:发送,微信,self,pyhton,chartype,UiaAPI,print,wx From: https://www.cnblogs.com/ybHsir/p/17876744.html