Windows版本微信客户端(非网页版)自动化,可实现简单的发送、接收微信消息

Overview

wxauto

Wechat Python

Windows版本微信客户端自动化,可实现简单的发送、接收微信消息,开发中

开发过程使用的微信版本:3.3.5

部分版本的微信可能由于UI界面不同从而无法使用,截至2021-09-05最新版本可用

安装

pip install wxauto

示例

from wxauto import *


# 获取当前微信客户端
wx = WeChat()


# 获取会话列表
wx.GetSessionList()


# 输出当前聊天窗口聊天消息
msgs = wx.GetAllMessage
for msg in msgs:
    print('%s : %s'%(msg[0], msg[1]))
## 获取更多聊天记录
wx.LoadMoreMessage()
msgs = wx.GetAllMessage
for msg in msgs:
    print('%s : %s'%(msg[0], msg[1]))


# 向某人发送消息(以`文件传输助手`为例)
msg = '你好~'
who = '文件传输助手'
wx.ChatWith(who)  # 打开`文件传输助手`聊天窗口
wx.SendMsg(msg)  # 向`文件传输助手`发送消息:你好~


# 向某人发送文件(以`文件传输助手`为例,发送三个不同类型文件)
file1 = 'D:/test/wxauto.py'
file2 = 'D:/test/pic.png'
file3 = 'D:/test/files.rar'
who = '文件传输助手'
wx.ChatWith(who)  # 打开`文件传输助手`聊天窗口
wx.SendFiles(file1, file2, file3)  # 向`文件传输助手`发送上述三个文件
# 注:为保证发送文件稳定性,首次发送文件可能花费时间较长,后续调用会缩短发送时间


# 向某人发送程序截图(以`文件传输助手`为例,发送微信截图)
name = '微信'
classname = 'WeChatMainWndForPC'
wx.ChatWith(who)  # 打开`文件传输助手`聊天窗口
wx.SendScreenshot(name, classname)  # 发送微信窗口的截图给文件传输助手

注:为保证发送文件稳定性,首次发送文件可能花费时间较长,后续调用会缩短发送时间

注意事项

目前还在开发中,测试案例较少,使用过程中可能遇到各种Bug

如果遇到问题或者有新的想法,希望您可以通过以下两种方式联系我进行改进:

最后

如果对您有帮助,希望可以帮忙点个Star,如果您正在使用这个项目,可以将右上角的 Unwatch 点为 Watching,以便在我更新或修复某些 Bug 后即使收到反馈,感谢您的支持,非常感谢!

Comments
  • 子线程中使用调用发送,报Can not load UIAutomationCore.dll.报错Can not load UIAutomationCore.dll.

    子线程中使用调用发送,报Can not load UIAutomationCore.dll.报错Can not load UIAutomationCore.dll.

    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。

    opened by xla145 4
  • 远程桌面运行还有一些问题

    远程桌面运行还有一些问题

    你好,我遇到了以下问题: from wxauto import * to_user = 'TEST' msg = 'hello' wx = WeChat() wx.ChatWith(to_user) wx.SendMsg(msg)

    1. 直接运行可以正常发送
    2. 计划任务运行无法找到窗体,(141) : Find Control Timeout: {ClassName: 'WeChatMainWndForPC', ControlType: WindowControl}(<class 'LookupError'>)
    3. 远程桌面运行,远程桌面打开窗口或者最大化的时候可以运行,远程桌面最小化或者关闭不能正常发送,管理员权限运行也不能解决这个问题

    下面是错误日志: 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}

    opened by VitoYane 3
  • wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}

    wxauto.py[48] SplitMessage -> Find Control Timeout(0s): {ControlType: ButtonControl}

    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}

    opened by zhifeng456 2
  • GetAllMessage TypeError

    GetAllMessage TypeError

    GetAllMessage() returned a TypeError that "list_object_is_not_callable" But there is not list type params I entered, who so? Is it my input fault or bug GetAllMessage_TypeError_list_object_is_not_callable ?

    opened by Davidyang1989 1
  • No module named

    No module named "win32gui"

    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+.

    opened by foool 0
  • 转发功能

    转发功能

    您好!非常感谢您做的这个pj,我在实际使用的过程中遇到了一些小问题,就是关于想要转发视频号的问题。我在使用过程中如果想要转发图片之类可以通过获取信息然后赋予变量的方式进行转发,但是视频号我在获取信息的时候返回的是一段数字,我在转发的时候就只能发送数字而无法发送视频了,所以想问一下能否进行进一步的交流?或者说您有没有可以解决的办法或者方案呢?再次感谢您的pj为我节省了许多的时间!

    opened by wuyunjiejie 0
  • 安装wxauto后,编译依然错误【急】

    安装wxauto后,编译依然错误【急】

    作者你好,我安装好wxauto后,使用示例代码进行测试,依然无法编译,请帮忙看一下是什么问题,谢谢。 错误显示如下: Traceback (most recent call last): File "c:\Users\John\Desktop\pythontest\wxauto-test.py", line 4, in wx = WeChat() NameError: name 'WeChat' is not defined

    详细错误如下图。

    xtiCr9.png

    https://imgse.com/i/xtiCr9

    xtiVPK.png

    https://imgse.com/i/xtiVPK

    opened by john000612 1
AutoX是一个高效的自动化机器学习工具,它主要针对于表格类型的数据挖掘竞赛。 它的特点包括: 效果出色、简单易用、通用、自动化、灵活。

English | 简体中文 AutoX是什么? AutoX一个高效的自动化机器学习工具,它主要针对于表格类型的数据挖掘竞赛。 它的特点包括: 效果出色: AutoX在多个kaggle数据集上,效果显著优于其他解决方案(见效果对比)。 简单易用: AutoX的接口和sklearn类似,方便上手使用。

4Paradigm 431 Dec 28, 2022