直接上代码
from pywechat.WechatAuto import get_chat_history
chat_history=get_chat_history(friend='好友或群聊名称',number=50,capture_screen=True,folder_path="E:\OneDrive\Desktop\获取聊天记录测试")
print(chat_history)
上述代码用到了pywechat中WechatAuto模块的get_chat_history函数
参数如下:
friend | 好友或群聊名称 |
number | 待获取的聊天记录条数,默认10条 |
capture_screen | 是否截取聊天记录保存为截图 |
folder_path | 聊天记录截图保存地址,若不传入,将会保存在运行代码的本地文件夹内 |
is_maximize | 微信主界面是否全屏,默认全屏 |
close_wechat | 获取聊天记录过程中是否关闭掉微信主界面,默认关闭 |
运行该函数,我们便可以轻松得到好友或群聊中最近50条的聊天记录和聊天记录的截图,返回结果为json
结果:
注意事项:
get_chat_history函数在最新版本的pywechat中
pip install pywechat127==1.8.6