用于抓取微信“小程序话题”下的公众号文章(贴图),并以 JSON 结构输出。
mp.weixin.qq.com ,不能在常见云服务商静态IP环境下运行,会触发验证码验证,
请在自己电脑上登陆过自己微信的情况下运行。pwsh -NoProfile -Command "python -m pip install -U requests playwright; python -m playwright install chromium"
pwsh -NoProfile -Command "python ./collect-app-msg.py --topic '#乡源文化挖掘' --out data.json"
常用参数:
--topic:必填。话题名称,例如 #乡源文化挖掘--out:输出文件名,默认 data.json--max-pages:最多抓取页数,默认 10(<=0 表示不限制)--sleep:每条之间延迟秒数,默认 0.3示例(只抓 1 页):
pwsh -NoProfile -Command "python ./collect-app-msg.py --topic '#乡源文化挖掘' --max-pages 1 "
输出文件:默认为 data.json 在同名目录下,是一个 JSON 数组,每条为文章结构:
[
{
"outlinkId": 2247483702,
"userId": 0,
"url": "https://mp.weixin.qq.com/s?...",
"title": "标题",
"images": ["https://.../0?wx_fmt=jpeg"],
"content": "<a class=\"wx_topic_link\" ...>...</a>\n"
}
]
字段说明:
outlinkId:微信官方文章的 msgid(用于去重)userId:从乡源小程序传入的用户ID,如果不是从小程序发出来的则为 0images:图片content:详情数据脚本会在抓取前读取 --out 指定的 JSON:
outlinkId;缺失时使用 urlgetTopicList 返回的某条文章已存在于历史 JSON 中,则不会再打开详情页getTopicList 的所有条目都已存在(本页没有任何新条目),则停止请求下一页outlinkId/url 时保留新条目)