【个人开发】通过python导出微信聊天记录

1. 背景

距离上一文章【个人开发】通过SQLite导出微信聊天记录已经过去快一年。

剩下一点小bug迟迟没完成,趁着近期比较有空,再研究一下,收个尾。

2. 写在前面

依旧先上效果:
在这里插入图片描述
主要思路:python解密db文件,存到csv文件。
微信文件说明:
wccontact_new2.db: 微信联系人信息
group_new.db: 群聊信息
Message: 消息记录

在这里插入图片描述

3. 步骤

3.0 环境配置

1、电脑:Mac
2、安装pysqlcipher3、sqlcipher。


# 安装sqlcipher
# 网上源码安装 也可以参考
brew install sqlcipher

# 安装pysqlcipher3
# 访问https://pypi.org/project/rotki-pysqlcipher3
# 下载whl文件
# 注意这里需要python3.11版本
pip install rotki_pysqlcipher3-2024.1.2-cp311-cp311-macosx_10_9_universal2.whl 

注:
之前其他方式安装到pysqlcipher3,报错:symbol not found in flat namespace '_sqlite3_aggregate_context’搞的很烦。上面这种安装方法没问题。

3.1 确保sqlcipher安装成功。

# 链接相应的db文件
sqlcipher msg_0.db

# 操作数据库
# key为上一篇文章中逆向工程得到的64位字符串,书写格式如下,以'x''开始
PRAGMA key='x''xxxxxxxxxxx1a62xxxxxxxxxxxxxxxxxxxxc7221423c''';
PRAGMA cipher_compatibility=3;
PRAGMA cipher_page_size=1024;
PRAGMA kdf_iter=64000;
PRAGMA cipher_hmac_algorithm=HMAC_SHA1;
PRAGMA cipher_kdf_algorithm=PBKDF2_HMAC_SHA1;
SELECT name FROM sqlite_master;

如果能返回数据列表,则证明链接成功。
在这里插入图片描述

3.2 python链接

import pandas as pd
import pysqlcipher3.dbapi2 as sqlite
db= sqlite.connect(path + filename)
db_cursor = db.cursor()
db_cursor.execute("PRAGMA key='x''ae2c362fed444615a72551aaaaaaabcc544fc79214e4d79acc144d''';")
db_cursor.execute("PRAGMA cipher_compatibility=3;")
db_cursor.execute("PRAGMA cipher_page_size=1024;")
db_cursor.execute("PRAGMA kdf_iter=64000;")
db_cursor.execute("PRAGMA cipher_hmac_algorithm=HMAC_SHA1;")
db_cursor.execute("PRAGMA cipher_kdf_algorithm=PBKDF2_HMAC_SHA1;")
db_cursor.execute("SELECT name FROM sqlite_master;")
data_list = db_cursor.fetchall()
table_df = pd.DataFrame(data_list)

以上,正常运行即可,想怎么玩都行。

项目github地址:wechatbackup.git

有问题的朋友,欢迎issues或者评论交流,如有收获,欢迎stars~

参考文章:
Mac安装pysqlcipher3
Mac系统 pip 安装 pysqlcipher3 失败的问题

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值