🚀 一个优雅的微博个人数据备份工具
采用现代异步架构 · 提供精美的 macOS 原生 GUI 界面和命令行工具
- 全量抓取:备份所有历史微博(文本、图片、视频)
- 断点续传:支持中断后继续,不重复下载
- 异步高效:使用异步 IO,支持高并发下载
- 精美展示:生成 Apple 风格的 HTML 离线页面
- 数据持久化:SQLite 数据库存储,方便查询和导出
- 双界面支持:macOS 原生 GUI + 命令行工具
从 Releases 页面下载适合你系统的版本:
- macOS: 下载
.dmg文件,双击安装即可 - Windows: 下载
.exe或.zip文件,解压后运行
无需安装 Python 环境,开箱即用!
见下方"安装步骤"部分。
- Python: 3.9 或更高版本
- 操作系统: macOS / Linux / Windows
- 依赖: 见
requirements.txt
git clone https://github.com/yourusername/weibo-backup.git
cd weibo-backuppython3 -m venv .venv
source .venv/bin/activate # macOS/Linux
# 或
.venv\Scripts\activate # Windowspip install -r requirements.txt复制配置模板并填写你的信息:
cp config.example.json config.json编辑 config.json,填入你的微博信息:
{
"weibo": {
"user_id": "你的用户ID",
"cookie": "你的Cookie",
"user_agent": "浏览器User-Agent"
}
}如何获取 Cookie:
- 打开 Chrome 浏览器
- 访问 https://m.weibo.cn 并登录
- 按
F12打开开发者工具 - 切换到 Console 标签
- 输入
document.cookie并回车 - 复制输出的 Cookie 字符串
如何获取 User ID:
- 登录微博后,访问你的主页
- 查看 URL,格式为
https://m.weibo.cn/u/1234567890 - 其中
1234567890就是你的 User ID
python run_gui.py启动后,你可以:
- 在 开始逃生 页面备份微博数据
- 在 逃生设置 页面管理配置和 Cookie
python run.py程序会自动执行:
- 测试连接
- 抓取微博数据
- 下载图片和视频
- 生成 HTML 页面
open data/output/index.html # macOS
# 或
xdg-open data/output/index.html # Linux
# 或直接在浏览器中打开该文件weibo-backup/
├── assets/ # 界面资源文件
├── config.json # 配置文件(需要自行创建)
├── config.example.json # 配置模板
├── requirements.txt # Python 依赖
├── run_gui.py # GUI 启动入口
├── run.py # 命令行启动入口
├── src/
│ ├── database.py # 数据库模块
│ ├── weibo_fetcher.py # 微博抓取模块
│ ├── media_downloader.py # 媒体下载模块
│ ├── html_generator.py # HTML 生成模块
│ ├── main.py # 命令行主程序
│ ├── gui/ # GUI 模块
│ └── pipeline/ # 数据处理管道
└── data/ # 数据目录(运行后自动生成)
├── weibo.db # SQLite 数据库
├── images/ # 下载的图片
├── videos/ # 下载的视频
└── output/
└── index.html # 生成的 HTML 页面
config.json 主要配置项:
{
"weibo": {
"user_id": "你的用户ID",
"cookie": "你的Cookie",
"user_agent": "浏览器User-Agent"
},
"crawler": {
"concurrent_requests": 5,
"concurrent_downloads": 20,
"request_delay": 1.0,
"retry_times": 3,
"timeout": 30
},
"storage": {
"database_path": "data/weibo.db",
"images_dir": "data/images",
"videos_dir": "data/videos",
"output_dir": "data/output"
}
}生成的 HTML 备份页面:
- ✨ Apple 风格设计,简洁优雅
- 📱 响应式布局,支持手机/平板/电脑
- 🖼️ 图片网格展示,支持灯箱预览
- 🎬 内联视频播放器
- 📊 数据统计和时间轴
- 🔍 完全离线可用,无需网络
以 6000 条微博为例:
- 抓取时间: 约 5-10 分钟
- 图片下载: 约 2-4 小时(假设 10000 张)
- 视频下载: 约 1-3 小时(假设 100 个)
- 存储空间: 约 15-50 GB
如果备份过程中断:
- 不要删除
data/weibo.db文件 - 直接重新运行程序
- 程序会自动从上次中断的地方继续
Q: Cookie 过期怎么办?
A: 在 GUI 界面的设置页面点击"更新 Cookie",或手动编辑 config.json 文件。数据不会丢失。
Q: 会被微博封号吗?
A: 程序有请求延迟和并发控制,模拟正常用户行为。正常使用不会触发反爬虫机制。
Q: 可以备份别人的微博吗?
A: 只能备份登录账号有权限查看的内容,无法突破隐私限制。
Q: 删除功能安全吗?
A: 本工具不提供删除功能,仅用于备份。如需删除微博,请使用微博官方功能。
Q: 数据存储在哪里?
A: 所有数据存储在 data/ 目录下,包括数据库、图片、视频和生成的 HTML 文件。
Q: macOS 打包后的 App 无法运行怎么办?
A: 如果遇到 "Incompatible processor" 或 "neon crc32" 错误,需要更新 PySide6 版本:
source .venv/bin/activate
pip uninstall -y PySide6 PySide6-Addons PySide6-Essentials shiboken6
pip install PySide6 # 安装最新版本 (6.10.1+)
./build_macos.sh # 重新打包这个问题通常发生在 Apple Silicon (M1/M2/M3) Mac 上,PySide6 6.7.3 版本存在兼容性问题。
- 本地运行:所有数据处理在本地完成,不上传到任何服务器
- Cookie 安全:
config.json已加入.gitignore,不会被提交到 Git - 开源透明:所有代码开源,可以自行审查
本工具仅供个人备份使用,请遵守微博服务条款和相关法律法规。使用本工具产生的任何后果由使用者自行承担。
欢迎提交 Issue 和 Pull Request!
本项目采用 MIT License - 查看 LICENSE 文件了解详情
立即开始备份你的微博记忆! 💙
🚀 An elegant personal data backup tool for Weibo
Built with modern asynchronous architecture · Beautiful macOS native GUI and CLI
- Complete Backup: Backup all historical Weibo posts (text, images, videos)
- Resume Support: Continue from where it left off, no duplicate downloads
- Async & Efficient: Built with async I/O for high-performance concurrent downloads
- Beautiful Display: Generate Apple-style offline HTML pages
- Data Persistence: SQLite database storage for easy queries and exports
- Dual Interface: macOS native GUI + command-line tool
Download the version for your system from Releases:
- macOS: Download
.dmgfile, double-click to install - Windows: Download
.exeor.zipfile, extract and run
No Python installation required - ready to use out of the box!
See "Installation" section below.
- Python: 3.9 or higher
- OS: macOS / Linux / Windows
- Dependencies: See
requirements.txt
git clone https://github.com/yourusername/weibo-backup.git
cd weibo-backuppython3 -m venv .venv
source .venv/bin/activate # macOS/Linux
# or
.venv\Scripts\activate # Windowspip install -r requirements.txtCopy the configuration template and fill in your information:
cp config.example.json config.jsonEdit config.json with your Weibo information:
{
"weibo": {
"user_id": "Your User ID",
"cookie": "Your Cookie",
"user_agent": "Browser User-Agent"
}
}How to Get Cookie:
- Open Chrome browser
- Visit https://m.weibo.cn and log in
- Press
F12to open Developer Tools - Switch to Console tab
- Type
document.cookieand press Enter - Copy the output Cookie string
How to Get User ID:
- After logging in, visit your profile page
- Check the URL, format is
https://m.weibo.cn/u/1234567890 1234567890is your User ID
python run_gui.pyAfter launching, you can:
- Backup Weibo data on the Lifeboat page
- Manage configuration and Cookie on the Settings page
python run.pyThe program will automatically:
- Test connection
- Fetch Weibo data
- Download images and videos
- Generate HTML pages
open data/output/index.html # macOS
# or
xdg-open data/output/index.html # Linux
# or open the file directly in your browserweibo-backup/
├── assets/ # UI resource files
├── config.json # Configuration file (create manually)
├── config.example.json # Configuration template
├── requirements.txt # Python dependencies
├── run_gui.py # GUI entry point
├── run.py # CLI entry point
├── src/
│ ├── database.py # Database module
│ ├── weibo_fetcher.py # Weibo fetcher module
│ ├── media_downloader.py # Media downloader module
│ ├── html_generator.py # HTML generator module
│ ├── main.py # CLI main program
│ ├── gui/ # GUI module
│ └── pipeline/ # Data processing pipeline
└── data/ # Data directory (auto-generated)
├── weibo.db # SQLite database
├── images/ # Downloaded images
├── videos/ # Downloaded videos
└── output/
└── index.html # Generated HTML page
Main config.json options:
{
"weibo": {
"user_id": "Your User ID",
"cookie": "Your Cookie",
"user_agent": "Browser User-Agent"
},
"crawler": {
"concurrent_requests": 5,
"concurrent_downloads": 20,
"request_delay": 1.0,
"retry_times": 3,
"timeout": 30
},
"storage": {
"database_path": "data/weibo.db",
"images_dir": "data/images",
"videos_dir": "data/videos",
"output_dir": "data/output"
}
}Generated HTML backup pages include:
- ✨ Apple-style design, clean and elegant
- 📱 Responsive layout, supports mobile/tablet/desktop
- 🖼️ Grid image gallery with lightbox preview
- 🎬 Inline video player
- 📊 Statistics and timeline
- 🔍 Fully offline, no network required
For 6000 Weibo posts:
- Fetching: ~5-10 minutes
- Image Download: ~2-4 hours (assuming 10000 images)
- Video Download: ~1-3 hours (assuming 100 videos)
- Storage: ~15-50 GB
If the backup process is interrupted:
- Do not delete the
data/weibo.dbfile - Simply restart the program
- It will automatically continue from where it left off
Q: What if the Cookie expires?
A: Click "Update Cookie" on the Settings page in GUI, or manually edit config.json. Your data will not be lost.
Q: Will my account be banned?
A: The program has request delays and concurrency controls to simulate normal user behavior. Normal usage won't trigger anti-crawler mechanisms.
Q: Can I backup someone else's Weibo?
A: You can only backup content your logged-in account has permission to view. Cannot bypass privacy restrictions.
Q: Is the delete function safe?
A: This tool does not provide delete functionality, only backup. To delete Weibo posts, please use the official Weibo features.
Q: Where is the data stored?
A: All data is stored in the data/ directory, including database, images, videos, and generated HTML files.
- Local Processing: All data processing is done locally, not uploaded to any servers
- Cookie Security:
config.jsonis in.gitignore, won't be committed to Git - Open Source: All code is open source for your review
This tool is for personal backup use only. Please comply with Weibo's Terms of Service and relevant laws and regulations. Users are responsible for any consequences of using this tool.
Issues and Pull Requests are welcome!
This project is licensed under the MIT License - see the LICENSE file for details
Start backing up your Weibo memories now! 💙
