微信消息导出 基础版本

目录

 一、基本介绍

二、环境配置

三、主体代码

四、结果展示


 

 一、基本介绍

基于wxauto库的一个自动化操作脚本,使用前请先在电脑登陆微信,并置于前台,然后执行脚本,在弹出的窗口中输入好友昵称,点击导出按钮后等待执行即可。由于是前台自动化操作,在脚本执行期间,请勿对电脑进行操作。等待脚本执行完毕,会输出导出信息,并在D盘生成一个格式为 输入的好友昵称.txt文档。该脚本功能十分简洁,并且只能导出文字信息,存在信息导出不全的风险。

二、环境配置

windows win11系统

 python版本 3.11.4。

6c6815063dc94ea38b602e27161d07bc.png

微信版本,2024年1月4号最新版本,3.9.8.25。

e6d4601d1d5d4583b1f2e76cb0e4f2d2.png

使用的库

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()

四、结果展示

00535ed10a6a4698a22d52c3028aa425.png

注意:输入需要导出的好友昵称,最好是全称,搜索是根据查询到的第一个结果导出。

2072b6a75db740a88aaa64f65dadb64a.png

最后在D盘输出结果。

 

 

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿木wh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值