抓取微信公众号文章并转换为 Markdown 格式。支持提取标题、作者、发布时间、封面图、正文内容(含图片、视频链接)。 当用户提到以下场景时触发: - 读取/抓取/下载微信公众号文章 - 将公众号文章转为 Markdown - 提取 mp.weixin.qq.com 链接内容 - 保存公众号文章到本地 - 微信...
抓取微信公众号文章( mp.weixin.qq.com 链接),提取完整内容并转换为 Markdown 格式保存到本地。
标题 — 文章标题
公众号名称 — 作者/来源
发布时间 — 文章发布日期
封面图 — 文章封面图片链接
正文内容 — 完整的文章正文,包含:
bash
python scripts/fetch_wechat_article.py <文章链接> [选项]
参数:
url — 微信公众号文章链接(必需)-o, --output — 输出目录(默认:当前目录)--images — 下载图片到本地(开发中)--json — 以 JSON 格式输出元数据示例:
bash
# 基本用法
python scripts/fetch_wechat_article.py "https://mp.weixin.qq.com/s/xxxxx"
# 指定输出目录
python scripts/fetch_wechat_article.py "https://mp.weixin.qq.com/s/xxxxx" -o ./articles
# 只输出 JSON 元数据
python scripts/fetch_wechat_article.py "https://mp.weixin.qq.com/s/xxxxx" --json
python
from scripts.fetch_wechat_article import fetch_article
result = fetch_article(
url="https://mp.weixin.qq.com/s/xxxxx",
output_dir="./articles"
)
print(result['title']) # 文章标题
print(result['author']) # 公众号名称
print(result['content']) # Markdown 正文
print(result['filepath']) # 保存的文件路径
生成的 Markdown 文件结构:
markdown
# 文章标题
**公众号**: 公众号名称
**发布时间**: 2024-01-01
**封面**: 
**原文链接**: https://mp.weixin.qq.com/s/xxxxx
---
正文内容...

[视频](视频链接)
requests 库(用于 HTTP 请求)安装依赖:
bash
pip install requests
mp.weixin.qq.com问题可能原因解决方案无法提取正文页面结构变化检查微信是否更新了页面结构返回 403被反爬拦截稍后再试,或更换 IP标题为空文章被删除/受限确认链接可在浏览器正常打开图片不显示微信 CDN 链接过期使用 --images 下载到本地