Wechat article fetcher

From wulaosiji/skills · View interactive version

Wechat article fetcher is an AI agent skill from the GitHub repository wulaosiji/skills. 微信公众号文章抓取工具,基于Playwright绕过微信反爬机制,获取完整文章内容,支持批量抓取和Markdown导出。 Use when: "抓取公众号文章", "获取微信文章内容", "微信文章转Markdown", "fetch WeChat article", "scrape WeChat content", "批量抓取微信文章", "WeChat to Markdown", "公众号内容归档". 基于Playwright模拟真实浏览器,稳定绕过微信反爬。Cross-references: content-extractor, rss-feed, document-hub, pdf.

How to use this skill

Skill file

⚠️ 已迁移: 本技能已迁移至 wulaosiji/founder-skills 的 china-content-research,推荐使用新版。本版本保留用于向后兼容。

WeChat Article Fetcher

微信公众号文章抓取工具,基于 Playwright,可绕过微信的反爬机制获取完整文章内容。

When to Use

Use this skill when:

Do NOT use this skill if:

Typical triggers:

Workflow

遵循六步推进法(探查→约束→证据→执行→验证→交付)完成操作。

  1. 探查 (Probe)

完整读取用户提供的URL,确认目标和约束:

  1. 约束 (Constrain)

验证输入完整性,设定抓取频率和边界。临时链接(含tempkey)会过期,必须使用原始永久链接。受阻时换通道,不降级交付物。

  1. 证据 (Evidence)

每个抓取结果必须来自微信服务器实际响应,不编造文章内容。记录抓取时间和原始URL作为可追溯证据。

  1. 执行 (Execute)

调用抓取脚本,先给影响与结论,再给行动和必要证据。

from skills.wechat_article_fetcher.wechat_fetcher import fetch_wechat_article

result = fetch_wechat_article(url="https://mp.weixin.qq.com/s/xxxxx")

处理结果:

if result['success']:
    print(f"标题: {result['title']}")
    print(f"内容: {result['content'][:500]}")

保存文件(可选):

  1. 验证 (Verify)

用不同于生成路径的方式回读输出——检查返回的success字段为True,标题非空,内容长度合理(>100字符)。批量抓取时抽查每个结果。

  1. 交付 (Deliver)

返回结构化结果,清理临时浏览器进程。

Output

返回字典格式:

{
    'title': '文章标题',
    'content': '完整正文内容(纯文本)',
    'url': '原始链接',
    'fetch_time': '2026-02-12 11:00:00',
    'success': True
}

如指定 output_path,同时将内容写入Markdown文件。

Guardrails

以下约束确保安全、可靠地使用本技能。

Anti-patterns

Constraints

Technical Constraints

  1. 浏览器依赖: 需要Playwright和Chromium
  2. 链接时效: 临时链接(含tempkey)会过期
  3. 内容限制: 仅提取文本,不下载媒体
  4. 频率限制: 建议控制抓取频率

Installation

pip install playwright
playwright install chromium

Usage

Command Line

# 基本用法
python3 skills/wechat-article-fetcher/wechat_fetcher.py \
  "https://mp.weixin.qq.com/s/xxxxx"

# 保存到文件
python3 skills/wechat-article-fetcher/wechat_fetcher.py \
  "https://mp.weixin.qq.com/s/xxxxx" \
  -o "output/article.md"

Python API

from skills.wechat_article_fetcher.wechat_fetcher import fetch_wechat_article

result = fetch_wechat_article(
    url="https://mp.weixin.qq.com/s/xxxxx",
    output_path="output/article.md"
)

if result['success']:
    print(f"标题: {result['title']}")
    print(f"内容: {result['content'][:500]}")

Why Playwright?

| Method | Feasibility | Notes |

|--------|-------------|-------|

| web_fetch | ❌ | 微信反爬,只能获取标题 |

| browser (Chrome) | ⚠️ | 需要连接已授权的Chrome实例 |

| Playwright | ✅ | 模拟真实浏览器,稳定可靠 |

Scraping Strategy

  1. 启动 headless Chromium
  2. 访问目标URL,等待网络空闲
  3. 执行JS提取正文(#js_content选择器)
  4. 返回纯文本内容

Use Cases

Use Case 1: 写书项目素材收集

import os
from datetime import datetime

url = "https://mp.weixin.qq.com/s/xxxxx"
filename = f"article-{datetime.now().strftime('%Y%m%d')}.md"
output_path = f"01-Projects/book-openclaw/01-raw-materials/community-cases/{filename}"

os.makedirs(os.path.dirname(output_path), exist_ok=True)
result = fetch_wechat_article(url, output_path)

Use Case 2: 批量抓取

urls = [
    "https://mp.weixin.qq.com/s/xxx1",
    "https://mp.weixin.qq.com/s/xxx2",
    "https://mp.weixin.qq.com/s/xxx3",
]

for url in urls:
    result = fetch_wechat_article(url)
    print(f"✅ {result['title']}" if result['success'] else f"❌ 失败: {url}")

Use Case 3: 子Agent任务

使用 wechat-article-fetcher skill 抓取链接 https://mp.weixin.qq.com/s/xxxxx
保存到 01-Projects/book-openclaw/01-raw-materials/community-cases/

Troubleshooting

Issue: Chromium Not Found

playwright install chromium

Issue: Empty Content

Issue: Timeout Error

Related Skills

About UniqueClub

Part of the UniqueClub toolkit — a collection of skills for AI-powered content creation and automation.

🌐 https://uniqueclub.ai

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.