当前位置: 代码网 > it编程>前端脚本>Python > Python wxauto无法安装的问题及完美解决方法

Python wxauto无法安装的问题及完美解决方法

2026年03月26日 Python 我要评论
一、问题描述我们在实现自动化发送微信消息的功能,需要wxauto工具包。但是,现在直接pip install wxauto无法下载。二、解决办法直接上github下载源码使用。https://gith

一、问题描述

我们在实现自动化发送微信消息的功能,需要wxauto工具包。
但是,现在直接pip install wxauto无法下载。

二、解决办法

直接上github下载源码使用。
https://github.com/cluic/wxauto/tree/main#

三、使用教程

下载源码后,直接用pycharm打开

新建test目录,新建test.py文件
example.md文件中拷贝案例代码测试即可。

example.md案例

1. 基本使用

from wxauto import wechat
# 初始化微信实例
wx = wechat()
# 发送消息
wx.sendmsg("你好", who="张三")
# 获取当前聊天窗口消息
msgs = wx.getallmessage()
for msg in msgs:
    print(f"消息内容: {msg.content}, 消息类型: {msg.type}")

2. 监听消息

from wxauto import wechat
from wxauto.msgs import friendmessage
import time
wx = wechat()
# 消息处理函数
def on_message(msg, chat):
    # 示例1:将消息记录到本地文件
    with open('msgs.txt', 'a', encoding='utf-8') as f:
        f.write(msg.content + '\n')
    # 示例2:自动下载图片和视频
    if msg.type in ('image', 'video'):
        print(msg.download())
    # 示例3:自动回复收到
    if isinstance(msg, friendmessage):
        msg.quote('收到')
    ...# 其他处理逻辑,配合message类的各种方法,可以实现各种功能
# 添加监听,监听到的消息用on_message函数进行处理
wx.addlistenchat(nickname="张三", callback=on_message)
# 保持程序运行
wx.keeprunning()
# ... 程序运行一段时间后 ...
# 移除监听
wx.removelistenchat(nickname="张三")

3. 处理好友申请

from wxauto import wechat
wx = wechat()
# 获取新的好友申请
newfriends = wx.getnewfriends(acceptable=true)
# 处理好友申请
tags = ['同学', '技术群']
for friend in newfriends:
    remark = f'备注_{friend.name}'
    friend.accept(remark=remark, tags=tags)  # 接受好友请求,并设置备注和标签

4. 使用打字机模式发送消息

from wxauto import wechat
wx = wechat()
# 普通文本发送
wx.sendtypingtext("你好,这是一条测试消息", who="张三")
# 使用@功能和换行
wx.sendtypingtext("各位好:\n{@张三} 请负责前端部分\n{@李四} 请负责后端部分", who="项目群")

5. 获取多个微信客户端/登录窗口

5.1 获取多个微信客户端
from wxauto import get_wx_clients
# 获取所有微信客户端
clients = get_wx_clients()
for client in clients:
    print(f"微信客户端: {client}")
5.2 获取多个登录窗口
from wxauto import get_wx_logins
# 获取所有微信客户端
login_windows = get_wx_logins()
# 关闭所有登录窗口
for login_window in login_windows:
    login_window.close()  # 关闭

6. 自动登录

from wxauto import loginwnd
wxpath = "d:/path/to/wechat.exe"
# 创建登录窗口
loginwnd = loginwnd(wxpath)
# 登录微信
loginwnd.login()

7. 获取登录二维码

from wxauto import loginwnd
wxpath = "d:/path/to/wechat.exe"
# 创建登录窗口
loginwnd = loginwnd(wxpath)
# 获取登录二维码图片路径
qrcode_path = loginwnd.get_qrcode()
print(qrcode)

8. 合并转发消息

from wxauto import wechat
from wxauto.msgs import humanmessage
wx = wechat()
# 打开指定聊天窗口
wx.chatwith("工作群")
# 获取消息列表
msgs = wx.getallmessage()
# 多选最后五条消息
n = 0
for msg in msgs[::-1]:
    if n >= 5:
        break
    if isinstance(msg, humanmessage):
        n += 1
        msg.multi_select()
# 执行合并转发
targets = [
    '张三',
    '李四
]
wx.mergeforward(targets)

9. 创建群聊

from wxauto import wechat
wx = wechat()
# 以“张三”聊天窗口,添加“李四”,形成群聊
wx.addgroupmembers(group='张三', members=['李四'])
# 简单等待
time.sleep(3)
# 修改群名
wx.managegroup(name='这是新群名')

到此这篇关于python wxauto无法安装的问题及完美解决方法的文章就介绍到这了,更多相关python wxauto无法安装内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com