当前位置:   article > 正文

【个人开发】通过python导出微信聊天记录_如何使用python导出企业微信的聊天内容

如何使用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 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

注:
之前其他方式安装到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;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

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

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

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

项目github地址:wechatbackup.git

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/857348
推荐阅读
相关标签
  

闽ICP备14008679号