xiaowei-system/skills/chinese-platform-extraction/SKILL.md

4.0 KiB
Raw Blame History

name version date description metadata tags
chinese-platform-extraction 1.0.1 2026-09-10 Use when extracting content from WeChat or Zhihu.
version author category
1.0.1 小唯 productivity
web-scraping
chinese-platforms
wechat
zhihiu
content-extraction

Chinese Platform Content Extraction

从中国平台(微信公众号、知乎等)提取内容的专用工作流。

When This Skill Activates

Use this skill when the user:

  • 提供微信公众号链接mp.weixin.qq.com
  • 提供知乎链接zhihu.com
  • 需要从中国平台提取文章内容
  • 遇到 403 或 CAPTCHA 问题

核心原则

  1. 优先使用 stealth 模式 — 中国平台反爬严格,普通请求易被 403
  2. 移动端 UA 更可靠 — Android UA 比桌面 UA 更不容易触发验证
  3. 元数据先于正文 — og:title 等元数据即使被 CAPTCHA 也能获取
  4. 不要批量爬取 — 连续请求 3-5 次后必触发验证

微信公众号mp.weixin.qq.com

方法 1curl + Python推荐

# 1. 拉取完整 HTMLAndroid 移动端 UA + Referer 头)
curl -sL --connect-timeout 10 \
  -H "User-Agent: Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.230 Mobile Safari/537.36" \
  -H "Referer: https://mp.weixin.qq.com/" \
  "https://mp.weixin.qq.com/s/ARTICLE_ID" 2>&1

方法 2Scrapling stealth备选

from scrapling.fetchers import StealthyFetcher

page = StealthyFetcher.fetch(url, headless=True, solve_cloudflare=True)
content = page.css('#js_content *::text').getall()

提取元数据(即使被 CAPTCHA 也能获取)

import re
html_text = open('page.html').read()

# 标题
title_match = re.search(r'<meta property="og:title"[^>]*content="([^"]+)"', html_text)
title = title_match.group(1) if title_match else "N/A"

# 描述
desc_match = re.search(r'<meta property="og:description"[^>]*content="([^"]+)"', html_text)
description = desc_match.group(1) if desc_match else "N/A"

坑点

  • CAPTCHA 随机触发:连续请求多次会触发环境验证
  • og:title 可绕过验证:即使被 CAPTCHA 挡住,元数据仍可读取
  • 不适合批量爬取:微信反爬严重,批量请求 3-5 次后必触发验证
  • 正文大小:一般 5000-15000 字符,通过 len(text) 确认是否完整

知乎zhihu.com

必须使用 stealth 模式

知乎普通请求返回 403必须使用 Scrapling stealth 模式:

from scrapling.fetchers import StealthyFetcher

url = "https://www.zhihu.com/pin/ARTICLE_ID"
page = StealthyFetcher.fetch(url, headless=True)

# 提取内容
content = page.css('.RichContent-inner .RichText *::text').getall()
for text in content:
    if text.strip():
        print(text[:100])

提取链接

links = page.css('.RichContent-inner a::attr(href)').getall()

坑点

  • 必须 headless=True:知乎检测浏览器自动化
  • 403 是常态:普通请求必被拒绝
  • 内容可能不完整:知乎懒加载,可能需要滚动

Scrapling 安装

# 安装 scrapling 完整版
pip install "scrapling[all]"

# 安装浏览器依赖
scrapling install
# 如果失败,手动安装 playwright
python3 -m playwright install chromium

工具选择决策树

中国平台内容提取
  │
  ├─→ 微信公众号
  │     ├─→ curl + Python首选快速
  │     └─→ Scrapling stealth备选更可靠
  │
  ├─→ 知乎
  │     └─→ Scrapling stealth必须普通请求 403
  │
  ├─→ 其他中国平台
  │     ├─→ 尝试 Scrapling stealth
  │     └─→ 如果失败,尝试 curl + 移动端 UA
  │
  └─→ 批量爬取
        └─→ 不推荐(反爬严重,易触发验证)

相关 Skill

  • web-content-extraction — 通用网页抓取工具链
  • scrapling — Scrapling 框架详细用法
  • duckduckgo-search — 免费搜索,可先搜索再抓取