Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

WeChat Article Reader Skill

一个供 Codex / Agents 使用的微信公众号公开文章读取 skill。输入 https://mp.weixin.qq.com/s/... 链接后,它会抓取页面并返回标题、作者、 发布时间、正文、原始链接和请求日志等结构化 JSON。

主要能力

  • 仅接受微信公众号公开文章链接,拒绝其他域名和路径
  • 使用 curl-cffi 模拟常见浏览器请求,降低普通 HTTP 请求被拦截的概率
  • 支持超时、有限次数重试和指数递增等待
  • 使用 Beautiful Soup 从页面中提取标题、作者、发布时间与正文
  • 清理常见跟踪参数,输出适合后续总结、检索或归档的 JSON
  • 不需要 API Key、微信登录、Cookie 或数据库

工作原理

用户提供公开文章 URL
        │
        ▼
校验域名、协议与 /s 路径
        │
        ▼
移除常见跟踪参数
        │
        ▼
curl-cffi 以 Chrome 请求特征抓取页面
        │
        ├── 请求异常:按设置重试并输出错误日志
        │
        ▼
Beautiful Soup 解析 HTML
        │
        ├── #activity-name / og:title  → 标题
        ├── #js_name / author meta     → 作者
        ├── published_time / ct        → 发布时间
        └── #js_content                → 正文纯文本
        │
        ▼
向标准输出返回 UTF-8 JSON

核心实现可以概括为:

if not is_public_wechat_article(url):
    return {"error": "invalid_url"}

html = fetch_with_curl_cffi(url, impersonate="chrome124")
soup = BeautifulSoup(html, "html.parser")

result = {
    "title": extract_title(soup),
    "author": extract_author(soup),
    "pub_time": extract_publish_time(soup, html),
    "content": soup.find(id="js_content").get_text("\n", strip=True),
}

环境要求

  • Codex 或兼容 SKILL.md 的 Agents 环境
  • Python 3.10+
  • uv
  • 可访问 mp.weixin.qq.com 的网络

macOS 可安装 uv

brew install uv

一条命令安装

使用 Codex 内置的 skill 安装器:

python3 ~/.codex/skills/.system/skill-installer/scripts/install-skill-from-github.py --repo DPXJ/wechat-article-reader-skill --path skills/wechat-article-reader

安装依赖:

cd ~/.codex/skills/wechat-article-reader && uv sync

完成后重启 Codex,使新 skill 生效。

如果没有 Codex 内置安装器,也可以直接克隆:

git clone https://github.com/DPXJ/wechat-article-reader-skill.git
mkdir -p ~/.codex/skills
cp -R wechat-article-reader-skill/skills/wechat-article-reader ~/.codex/skills/
cd ~/.codex/skills/wechat-article-reader && uv sync

直接运行

cd ~/.codex/skills/wechat-article-reader
uv run python scripts/read_wechat_article.py "https://mp.weixin.qq.com/s/..."

可选参数:

--timeout SECONDS       单次请求超时,默认 20 秒
--max-retries N         最大尝试次数,默认 3 次
--retry-delay SECONDS   重试基准等待时间,默认 1.0 秒

成功输出示例:

{
  "title": "文章标题",
  "pub_time": "发布时间",
  "author": "作者",
  "content": "正文纯文本",
  "source_url": "https://mp.weixin.qq.com/s/...",
  "strategy": "curl_cffi",
  "logs": {
    "http_status": 200,
    "attempts": []
  }
}

隐私与安全

  • 本项目不包含或要求 API Key、访问令牌、账号密码、Cookie 等秘密信息。
  • 不收集遥测数据,不把文章内容上传到第三方服务。
  • 请求只会发往用户输入且通过校验的 mp.weixin.qq.com 链接;微信服务器仍会像处理普通网页访问一样看到请求 IP 和请求头。
  • URL 会出现在本机命令历史与程序输出中。若原链接含有不希望保留的参数,请先自行检查。
  • logs 可能包含底层网络错误信息;公开分享日志前建议检查其中是否含本机网络环境信息。
  • 仅用于读取用户有权访问的公开内容。请遵守适用法律、微信平台规则及文章版权要求。

本仓库的 MIT License 只授权本项目代码,不授予任何被读取文章的内容版权。

项目结构

.
├── README.md
├── LICENSE
└── skills/
    └── wechat-article-reader/
        ├── SKILL.md
        ├── agents/openai.yaml
        ├── pyproject.toml
        ├── uv.lock
        └── scripts/read_wechat_article.py

License

MIT

About

Codex skill for reading public WeChat articles into structured JSON

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages