微信公众号文章链接处理。当用户发送微信公众号文章链接时,自动获取并提取文章内容。 触发条件:(1) 用户发送 http(s)://mp.weixin.qq.com/s/ 开头的链接 (2) 用户请求获取公众号文章内容
公众号文章链接特征:
mp.weixin.qq.com/s/ 开头https://mp.weixin.qq.com/s/abc123def456⚠️ 微信服务器会检测请求头,必须携带正常浏览器的 User-Agent,否则返回 403。
本地 CLI,urllib + certifi + 真实 UA,自带重试(最多 3 次)。失败时 stderr 提示是否改用 browser。
# 安装依赖(首次)
pip install -r requirements.txt
# 调用
python scripts/get_content.py --url "https://mp.weixin.qq.com/s/xxx"
仅在脚本返回非 0 且 stderr 建议改用 browser 时使用:
browser(action="navigate", url="用户发送的链接")
browser(action="snapshot")
公众号页面结构:
#page-content 元素中#activity-name 或 h1 标签.account_nickname 或类似元素mp.weixin.qq.com/s/ 链接get_content.py --url <链接>