微信公众号文章抓取工具 v3.0,在 v2.0 基础上新增: 免登录模式、 批量抓取、 图片下载、 多格式输出。
特性说明✅ 免登录模式无需扫码登录,直接抓取公开文章✅ 批量抓取支持从文件读取多个 URL 批量下载✅ 图片下载自动下载文章图片到本地✅ 多格式输出Markdown/HTML/JSON/TXT 四种格式
版本适用场景资源需求批量抓取Lite 版快速抓取、低内存环境低(无需浏览器)✅ 支持Playwright 版需要 Cookie 登录、复杂页面高(需 Chromium)✅ 支持
bash
# 基本用法
python3 scripts/wechat_fetch_lite.py "https://mp.weixin.qq.com/s/xxxxx"
# 指定输出格式
python3 scripts/wechat_fetch_lite.py "https://mp.weixin.qq.com/s/xxxxx" \
--format html --output article.html
# 下载图片
python3 scripts/wechat_fetch_lite.py "https://mp.weixin.qq.com/s/xxxxx" \
--download-images --output article.md
# 批量抓取
python3 scripts/wechat_fetch_lite.py --batch urls.txt --output ./articles \
--format markdown --delay 3
bash
# 免登录模式
python3 scripts/wechat_fetch_v3.py "https://mp.weixin.qq.com/s/xxxxx" --no-login
# Cookie 模式(需预先登录)
python3 scripts/wechat_fetch_v3.py "https://mp.weixin.qq.com/s/xxxxx"
# 批量抓取(带重试)
python3 scripts/wechat_fetch_v3.py --batch urls.txt --output ./articles \
--no-login --max-retries 3 --retry-delay 5
bash
# 创建 URL 列表文件 urls.txt
echo "https://mp.weixin.qq.com/s/xxx1" > urls.txt
echo "https://mp.weixin.qq.com/s/xxx2" >> urls.txt
echo "https://mp.weixin.qq.com/s/xxx3" >> urls.txt
# 批量抓取
python3 scripts/wechat_fetch_v3.py --batch urls.txt --output ./articles \
--no-login --download-images --format markdown
Lite 版(推荐):
python
from scripts.wechat_fetch_lite import WeChatFetcherLite
fetcher = WeChatFetcherLite()
# 单篇抓取
result = fetcher.fetch_single(
url="https://mp.weixin.qq.com/s/xxxxx",
download_images=True,
output_format="markdown"
)
Playwright 版:
python
from scripts.wechat_fetch_v3 import WeChatFetcher
fetcher = WeChatFetcher()
# 单篇抓取
result = fetcher.fetch_single(
url="https://mp.weixin.qq.com/s/xxxxx",
no_login=True,
download_images=True,
output_format="markdown"
)
# 批量抓取
results = fetcher.fetch_batch(
urls=["url1", "url2", "url3"],
output_dir="./articles",
no_login=True,
download_images=True,
output_format="json"
)
参数说明默认值url微信文章 URL--o, --output输出文件路径---batch批量抓取文件(每行一个URL)---download-images下载图片到本地False--format输出格式 (markdown/html/json/txt)markdown--timeout超时时间(秒)30--delay请求间隔(秒)2
参数说明默认值url微信文章 URL--o, --output输出文件/目录路径---batch批量抓取文件路径---no-login免登录模式False--download-images下载图片到本地False--format输出格式 (markdown/html/json/txt)markdown--headless无头模式True--timeout超时时间(秒)30--max-retries最大重试次数(批量模式)3--retry-delay重试间隔(秒)5
格式说明适用场景Markdown标准 Markdown,含元数据通用,推荐HTML完整 HTML 页面网页展示JSON结构化数据程序处理TXT纯文本简单阅读
特性Lite 版Playwright 版 (v3)Cookie 模式 (v2)资源需求低高高速度快中等中等稳定性高中高Cookie 登录❌✅✅批量抓取✅✅❌图片下载✅✅✅多格式输出✅✅✅重试机制❌✅❌推荐场景日常使用复杂需求私密文章
bash
# 1. 准备 URL 文件
cat > urls.txt << 'EOF'
https://mp.weixin.qq.com/s/article1
https://mp.weixin.qq.com/s/article2
https://mp.weixin.qq.com/s/article3
EOF
# 2. 执行批量抓取
python3 scripts/wechat_fetch_v3.py \
--batch urls.txt \
--output ./articles \
--no-login \
--download-images \
--format markdown
# 3. 查看结果
ls ./articles/
# article_001.md article_002.md article_003.md images/ batch_report.json
使用 --download-images 参数时:
images/ 子目录text
articles/
├── article_001.md
├── article_002.md
└── images/
├── image_001.jpg
├── image_002.png
└── image_003.gif
可能原因:
解决:
--timeout 时间可能原因:
解决:
解决:
batch_report.json 了解失败详情bash
pip install playwright beautifulsoup4 requests
playwright install chromium
MIT-0 · Free to use, modify, and redistribute. No attribution required.