cluic / wxauto Goto Github PK
View Code? Open in Web Editor NEWWindows版本微信客户端(非网页版)自动化,可实现简单的发送、接收微信消息,简单微信机器人
License: MIT License
Windows版本微信客户端(非网页版)自动化,可实现简单的发送、接收微信消息,简单微信机器人
License: MIT License
有新消息即要处理
尊敬的开发者,你好,我在用wxauto库来提醒他人进行疫情登记时,程序总是在发送前几个人的信息后就不再寻找聊天框了,接着就停止报错了,想请问一下如何解决这个问题。
代码:
from configparser import LegacyInterpolation
from wxauto import *
import time
wx = WeChat()
wx.GetSessionList()
leng=["张伟林","郑昊东","夏槟","郑剑锋","陈鹏理","范新森","罗鹏","邱斌","黄孝鹏","洪宇","吴昊彬",]
for i in leng:
msg = '1'
who = i
wx.ChatWith(who)
wx.SendMsg(msg)
报错:
Traceback (most recent call last):
File "d:/爬虫框架/120.py", line 20, in
wx.ChatWith(who) # 打开文件传输助手
聊天窗口
File "D:\anaconda3\lib\site-packages\wxauto\wxauto.py", line 196, in ChatWith
rollresult = roll_to()
File "D:\anaconda3\lib\site-packages\wxauto\wxauto.py", line 193, in roll_to
self.SessionList.ListItemControl(Name=who).Click(simulateMove=False)
File "D:\anaconda3\lib\site-packages\uiautomation\uiautomation.py", line 6542, in Click
point = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove)
File "D:\anaconda3\lib\site-packages\uiautomation\uiautomation.py", line 6503, in MoveCursorToInnerPos
rect = self.BoundingRectangle
File "D:\anaconda3\lib\site-packages\uiautomation\uiautomation.py", line 5906, in BoundingRectangle
rect = self.Element.CurrentBoundingRectangle
File "D:\anaconda3\lib\site-packages\uiautomation\uiautomation.py", line 6220, in Element
self.Refind(maxSearchSeconds=TIME_OUT_SECOND, searchIntervalSeconds=self.searchInterval)
File "D:\anaconda3\lib\site-packages\uiautomation\uiautomation.py", line 6471, in Refind
raise LookupError('Find Control Timeout({}s): {}'.format(maxSearchSeconds, self.GetSearchPropertiesStr()))
LookupError: Find Control Timeout(10s): {Name: '陈鹏理', ControlType: ListItemControl}
It can open conversation but failed at input text and send. OK with Chinese UI.
hi 老哥:
我在用wx.GetAllMessage[-6:] 取置顶群的最后几个消息的时候(大约1s取一次),如果群里出现某人拍了拍某人,监控就会不停的出现下面的打印,请问下有什么方法可以处理吗?谢谢。
2022-08-15 20:59:33.273 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:34.406 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:35.537 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:36.669 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:37.817 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:38.956 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:40.087 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:41.227 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:42.372 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:43.552 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:44.731 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:45.924 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:47.099 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:48.267 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:49.452 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:50.637 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:51.819 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:53.016 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:54.229 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:55.368 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-15 20:59:56.566 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
比如实时监听某个微信群最新消息, 如果消息中出现了某个关键词就发出提醒
from wxauto import *
wx = WeChat()
msgs = wx.GetLastMessage
while True:
if msgs == wx.GetLastMessage:
continue
else:
msgs = wx.GetLastMessage
# 后续对最新msgs进行处理
# ...
不知道这样写可不可以, 还是有更好的监听函数可以直接调用呢, 请大佬教我
text = “””通知:
疫情形势
公告
”””
wx.SendMsg(text)
就这种情况发出去的内容是连在一块儿的
通知:疫情形势公告
您好,请问长文本怎么换行发消息
我在使用过程中发现偶尔会将对话的窗口从微信主窗口中单独拖出来,导致后续无法发送信息;
是否可以添加一个发送信息完成后关闭对话框的操作(无论是主窗口还是偶尔打开的独立对话窗口),来避开这个问题
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/wxauto-main/main.py", line 210, in
wx.SendMsg(message)
File "C:\Users\Administrator\Desktop\wxauto-main\utils\wxauto.py", line 209, in SendMsg
self.EditMsg.SendKeys(msg, waitTime=0)
File "C:\Users\Administrator\Desktop\wxauto-main\venv\lib\site-packages\uiautomation\uiautomation.py", line 6740, in SendKeys
SendKeys(text, interval, waitTime, charMode)
File "C:\Users\Administrator\Desktop\wxauto-main\venv\lib\site-packages\uiautomation\uiautomation.py", line 2790, in SendKeys
SendUnicodeChar(key[0], charMode)
File "C:\Users\Administrator\Desktop\wxauto-main\venv\lib\site-packages\uiautomation\uiautomation.py", line 2587, in SendUnicodeChar
scan = ord(char)
TypeError: ord() expected a character, but string of length 3 found
远程桌面链接到远程电脑运行WXAUTO调用微信发送微信消息,远程桌面断开后,就不能调用窗口发送消息。请问有什么办法解决后台运行调用窗口发送消息的?windows环境
程序运行到msgs = wx.GetAllMessage时提示[WinError -2147221008] 尚未调用 CoInitialize,请问是怎么回事,谢谢!
您好!非常感谢您做的这个pj,我在实际使用的过程中遇到了一些小问题,就是关于想要转发视频号的问题。我在使用过程中如果想要转发图片之类可以通过获取信息然后赋予变量的方式进行转发,但是视频号我在获取信息的时候返回的是一段数字,我在转发的时候就只能发送数字而无法发送视频了,所以想问一下能否进行进一步的交流?或者说您有没有可以解决的办法或者方案呢?再次感谢您的pj为我节省了许多的时间!
Try to use wxauto.py file directly and install the required packages manually, but meet a no module named 'win32gui'
problem.
I have tried to install win32gui with the command pip install win32gui
, but failed.
The alternative way is pip install pywin32
The latest win32gui was released on Aug 16, 2017, some features may not be compatible with Python 3.7+.
win = uia.WindowControl(ClassName='WeChatMainWndForPC')
nick_name_button = win.ButtonControl()
nick_name = nick_name_button.Name
if nick_name is None or nick_name == '':
print('获取当前微信昵称时发生异常!')
return None
print('正在同步微信用户昵称为【{}】的系统数据...'.format(nick_name))
try:
if not win.IsTopmost():
win.SetActive()
win.SetTopmost(True)
nick_name_button.Click()
wechat_id_editor = win.GetFirstChildControl().GetFirstChildControl().GetNextSiblingControl().GetFirstChildControl().GetFirstChildControl().GetFirstChildControl().GetFirstChildControl().GetNextSiblingControl().GetLastChildControl()
wechat_id = wechat_id_editor.Name
except Exception as e:
print('获取当前微信号发生异常:{}'.format(e))
else:
print('当前微信号为:{}'.format(wechat_id))
给微信公众号的服务号发消息时候,因为服务号默认初始页面不是消息输入框,就会报错发送失败,有办法破没?
另外貌似无法唤醒缩小到右下角只剩下一个图标的微信,win19x64 wx 3.3.5.50
请问如何实现自动加好友呀?
尊敬的开发者,你好
我用的python3.10版本是不兼容现在的wxauto版本吗,为什么我程序循环定时发送信息,只能发几个人就抛异常,我也换了搜索方式也是一样的效果这是什么情况呢?
""" 添加pasteType="0" 最新3.7.5版本的适配 """
copydata = COPYDICT[i].replace(b'', key.encode()).replace(b'type="0"',
b'type="3"')
这个方案确定挺不错的,用了一段时间,但基于ui还是有些局限,最近花时间研究了下,也开源了一个更简易的python接口
找微信用户的时候,会出现翻过页的情况,一旦翻过页,程序认为已找到用户,但是又点击不到用户,就直接报错退出了
Can not load UIAutomationCore.dll.
1, You may need to install Windows Update KB971513 if your OS is Windows XP, see https://github.com/yinkaisheng/WindowsUpdateKB971513ForIUIAutomation
2, you need to use an UIAutomationInitializerInThread object in a thread, see demos/uiautomation_in_thread.py
[2021-12-02 14:03:24,284] ERROR in app: Exception on /send_msg [POST]
Traceback (most recent call last):
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\flask\app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\flask\app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "E:\xla\runjian\python\stock-manage\app.py", line 11, in send_msg
wx.ChatWith(who)
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\wxauto\wxauto.py", line 185, in ChatWith
self.UiaAPI.SwitchToThisWindow()
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 7437, in SwitchToThisWindow
if self.IsTopLevel():
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 6765, in IsTopLevel
handle = self.NativeWindowHandle
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 6094, in NativeWindowHandle
handle = self.Element.CurrentNativeWindowHandle
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 6218, in Element
self.Refind(maxSearchSeconds=TIME_OUT_SECOND, searchIntervalSeconds=self.searchInterval)
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 6466, in Refind
if not self.Exists(maxSearchSeconds, searchIntervalSeconds, False if raiseException else DEBUG_EXIST_DISAPPEAR):
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 6416, in Exists
control = FindControl(self.searchFromControl, self._CompareFunction, self.searchDepth, False, self.foundIndex)
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 8315, in FindControl
control = GetRootControl()
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 8093, in GetRootControl
return Control.CreateControlFromElement(AutomationClient.instance().IUIAutomation.GetRootElement())
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 52, in instance
cls.instance = cls()
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 69, in init
raise ex
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\uiautomation\uiautomation.py", line 60, in init
self.IUIAutomation = comtypes.client.CreateObject("{ff48dba4-60ef-4201-aa87-54103eef594e}", interface=self.UIAutomationCore.IUIAutomation)
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\comtypes\client_init.py", line 238, in CreateObject
obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
File "D:\Users\xulia\miniconda3\envs\pytest-auto\lib\site-packages\comtypes_init.py", line 1219, in CoCreateInstance
_ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
File "_ctypes/callproc.c", line 922, in GetResult
OSError: [WinError -2147221008] 尚未调用 CoInitialize。
消息的唯一ID在两次读取消息中,显示的唯一ID不一致。
能否修复下该问题,或者说明下这个问题是由于什么导致的,消息的唯一ID可以保持一致的话,就可以很便捷的读取全量消息了
您好,这个功能很强大,赞!
想问一下有不打开窗口发消息的方法吗?
微信发送文件时失败:提示'0'是一个空文件,无法发送,请重新选择!文件路径都是正确,发送消息框内容为空
你好请问当前库,有提供消息转发和获取好友列表的API吗
基本功能够了,给力!
消息如果是图片的话,输出是:【图片】,怎么才能得到真实的图片呢?我需要把图片发到文字识别api中。
不胜感激!
能否有个实时读取微信群聊 并发送文件给具体群聊的人
感谢
Line 251 in a1eb6e4
改为
copydata = COPYDICT[i].replace(b'<EditElement type="0" pasteType="0"><![CDATA[ ]]>', key.encode()).replace(b'type="0"', b'type="3"')
怎么获取卡片怎么获取卡片
大佬,怎么保存图片
请问支持时间检索吗,例如我获取十分钟的微信聊天记录
微信后台运行时,无法发送消息,可以添加以下代码先把微信调到前台。
import subprocess
subprocess.Popen('C:\Program Files (x86)\Tencent\WeChat\WeChat.exe')
wx.ChatWith(who) 这里的who支持列表不?
太给力了,希望一直更新
这代码写的真给力,厉害厉害
我测试了下 真是很给力
您好 我想咨询一下 如果现在微信更新版本 这个代码还能用吗?
还有 每次发送消息都会弹出微信 可以不弹出吗?
你好,我遇到了以下问题:
from wxauto import *
to_user = 'TEST'
msg = 'hello'
wx = WeChat()
wx.ChatWith(to_user)
wx.SendMsg(msg)
下面是错误日志:
2021-09-10 19:15:31.645 wxauto.py[210] SendMsg -> 2021-09-10 19:15:32.432 wxauto.py[193] roll_to -> Can not move cursor. ListItemControl's BoundingRectangle is (0,0,0,0)[0x0]. SearchProperties: {Name: 'TEST', ControlType: ListItemControl}
2021-09-10 19:15:43.033 wxauto.py[210] SendMsg -> Find Control Timeout: {Name: '输入', ControlType: EditControl}
2021-09-10 19:15:33.051 wxauto.py[193] roll_to -> Can not move cursor. ListItemControl's BoundingRectangle is (0,0,0,0)[0x0]. SearchProperties: {Name: 'TEST', ControlType: ListItemControl}
2021-09-10 19:15:43.589 wxauto.py[210] SendMsg -> Find Control Timeout: {Name: '输入', ControlType: EditControl}
2021-09-10 19:15:44.476 wxauto.py[193] roll_to -> Can not move cursor. ListItemControl's BoundingRectangle is (0,0,0,0)[0x0]. SearchProperties: {Name: 'TEST', ControlType: ListItemControl}
2021-09-10 19:15:55.037 wxauto.py[210] SendMsg -> Find Control Timeout: {Name: '输入', ControlType: EditControl}
2021-09-10 19:15:45.001 wxauto.py[193] roll_to -> Can not move cursor. ListItemControl's BoundingRectangle is (0,0,0,0)[0x0]. SearchProperties: {Name: 'TEST', ControlType: ListItemControl}
2021-09-10 19:15:55.579 wxauto.py[210] SendMsg -> Find Control Timeout: {Name: '输入', ControlType: EditControl}
2021-09-10 19:15:56.468 wxauto.py[193] roll_to -> Can not move cursor. ListItemControl's BoundingRectangle is (0,0,0,0)[0x0]. SearchProperties: {Name: 'TEST', ControlType: ListItemControl}
2021-09-10 19:16:07.052 wxauto.py[210] SendMsg -> Find Control Timeout: {Name: '输入', ControlType: EditControl}
2021-09-10 19:15:56.986 wxauto.py[193] roll_to -> Can not move cursor. ListItemControl's BoundingRectangle is (0,0,0,0)[0x0]. SearchProperties: {Name: 'TEST', ControlType: ListItemControl}
2021-09-10 19:16:07.563 wxauto.py[210] SendMsg -> Find Control Timeout: {Name: '输入', ControlType: EditControl}
2021-09-10 19:16:08.952 wxauto.py[193] roll_to -> Can not move cursor. ListItemControl's BoundingRectangle is (0,0,0,0)[0x0]. SearchProperties: {Name: 'TEST', ControlType: ListItemControl}
2021-09-10 19:16:19.523 wxauto.py[210] SendMsg -> Find Control Timeout: {Name: '输入', ControlType: EditControl}
2021-09-10 19:16:21.103 wxauto.py[193] roll_to -> Can not move cursor. ListItemControl's BoundingRectangle is (0,0,0,0)[0x0]. SearchProperties: {Name: 'TEST', ControlType: ListItemControl}
2021-09-10 19:16:31.683 wxauto.py[210] SendMsg -> Find Control Timeout: {Name: '输入', ControlType: EditControl}
2021-09-10 19:16:33.901 wxauto.py[193] roll_to -> Can not move cursor. ListItemControl's BoundingRectangle is (0,0,0,0)[0x0]. SearchProperties: {Name: 'TEST', ControlType: ListItemControl}
2021-09-10 19:16:44.501 wxauto.py[210] SendMsg -> Find Control Timeout: {Name: '输入', ControlType: EditControl}
试了一下,接受的文字消息可以保存,但是图片消息就显示为【图片】,好像没法自定义保存!
所以想请教一下,接收到的图片能自定义保存到指定的文件夹吗?谢谢!
def ChatWith(self, who, RollTimes=None):
'''
打开某个聊天框
who : 要打开的聊天框好友名,str; * 最好完整匹配,不完全匹配只会选取搜索框第一个
RollTimes : 默认向下滚动多少次,再进行搜索
'''
self.UiaAPI.SwitchToThisWindow()
RollTimes = 10 if not RollTimes else RollTimes
RollTimes = 0
RollTimes入参给0 不想再最近联系人列表搜索
但是 if not 0 = True , RollTimes又被赋值10 还是在最近联系人列表查找了
查sessionlist、发消息 功能可以工作了。但有很多报错:
2022-08-16 11:34:18.984 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-16 11:34:19.264 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
2022-08-16 11:34:19.548 wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}
windows客户端点选已关注公众号后,可以看到文章总数
滑动滚轮即可不断刷新文章
我看了下代码 是不是可以直接改造这个
def getArticles(self, who, RollTimes=None):
'''
打开某个聊天框
who : 要打开的聊天框好友名,str; * 最好完整匹配,不完全匹配只会选取搜索框第一个
RollTimes : 默认向下滚动多少次,再进行搜索
'''
self.UiaAPI.SwitchToThisWindow()
RollTimes = 10 if not RollTimes else RollTimes
def roll_to(who=who, RollTimes=RollTimes):
for i in range(RollTimes):
if who not in self.GetSessionList()[:-1]:
self.SessionList.WheelDown(wheelTimes=3, waitTime=0.1*i)
else:
time.sleep(0.5)
self.SessionList.ListItemControl(Name=who).Click(simulateMove=False)
return 1
return 0
rollresult = roll_to()
if rollresult:
return 1
else:
self.Search(“订阅号”)
return roll_to(RollTimes=1)
按照咱定义的roll方法 把“订阅号”当成chatwith里的who,roll应该是可以选中的,然后就是要再其中search 具体公众号名称,然后选中,又是一波滚动,文章没有的话,这个滚轮是动不了的,最后就是把文章名称 发布时间 link拿到
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.