目录
一、基本介绍
基于wxauto库的一个自动化操作脚本,使用前请先在电脑登陆微信,并置于前台,然后执行脚本,在弹出的窗口中输入好友昵称,点击导出按钮后等待执行即可。由于是前台自动化操作,在脚本执行期间,请勿对电脑进行操作。等待脚本执行完毕,会输出导出信息,并在D盘生成一个格式为 输入的好友昵称.txt文档。该脚本功能十分简洁,并且只能导出文字信息,存在信息导出不全的风险。
二、环境配置
windows win11系统
python版本 3.11.4。
微信版本,2024年1月4号最新版本,3.9.8.25。
使用的库
from wxauto import *
import time
from tkinter import *
其中time和tkinter是python自带的库,wxauto安装使用此命令:
pip install wxauto -i https://pypi.tuna.tsinghua.edu.cn/simple
wxauto github地址:https://github.com/cluic/wxauto
三、主体代码
from wxauto import *
import time
from tkinter import *
wx = WeChat()
def theTest(name):
#获取指定好友信息
msglist = []
wx.ChatWith(name)
msglist.append(wx.GetAllMessage)
while True:
print("延时后滑动...")
time.sleep(1.5)
wx.LoadMoreMessage()
msgs = wx.GetAllMessage
if msgs == msglist[-1]:
print("开始写入消息记录")
break
else:
msglist.append(msgs)
msgs_res = reversed(msgs)
try:
with open(file=f"D:\\{name}.txt", mode="w", encoding='utf-8') as wfile:
for li in msgs_res:
wfile.write(f"{li[0]}:{li[1]}\n")
print("写入成功!")
except:
print("写入失败!")
return False
if __name__ == '__main__':
root = Tk()
name_la = Label(root,text="好友名字:")
e = Entry(root)
cha_b = Button(root, text="导出", command=lambda: theTest(e.get()))
name_la.grid(row=1, column=1)
e.grid(row=1, column=2)
cha_b.grid(row=1, column=3)
root.mainloop()
四、结果展示
注意:输入需要导出的好友昵称,最好是全称,搜索是根据查询到的第一个结果导出。
最后在D盘输出结果。