mcpField
C
china-news-crawler

china-news-crawler

github.com/nanmicoderData & databases635118 installsUpdated 12w ago
Repository

About china-news-crawler

china-news-crawler is a skill for extracting articles from major Chinese news platforms. It detects the platform from a URL and saves the content as JSON and Markdown.

Key features

  1. 01Supports five Chinese news platforms
  2. 02Detects platform from URL
  3. 03Extracts article content and metadata
  4. 04Outputs JSON and Markdown
  5. 05Allows a custom output directory

Use cases

  1. 01Archive WeChat public account articles
  2. 02Extract Toutiao news articles
  3. 03Convert news articles into structured data

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/nanmicoder/newscrawler --skill china-news-crawler

After installing, type/china-news-crawlerin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
platform-patterns.md
scripts/
detector.py
extract_news.py
formatter.py
models.py
scripts/crawlers/
__init__.py
base.py
fetchers.py
netease.py
sohu.py
tencent.py
toutiao.py
wechat.py

Details

From the project README

China News Crawler Skill

从中国主流新闻平台提取文章内容,输出 JSON 和 Markdown 格式。

独立可迁移:本 Skill 包含所有必需代码,无外部依赖,可直接复制到其他项目使用。

支持平台

平台IDURL 示例
微信公众号wechathttps://mp.weixin.qq.com/s/xxxxx
今日头条toutiaohttps://www.toutiao.com/article/123456/
网易新闻neteasehttps://www.163.com/news/article/ABC123.html
搜狐新闻sohuhttps://www.sohu.com/a/123456_789
腾讯新闻tencenthttps://news.qq.com/rain/a/20251016A07W8J00

使用方式

基本用法
# 提取新闻,自动检测平台,输出 JSON + Markdown
uv run .claude/skills/china-news-crawler/scripts/extract_news.py "URL"

# 指定输出目录
uv run .claude/skills/china-news-crawler/scripts/extract_news.py "URL" --output ./output

# 仅输出 JSON
uv run .claude/skills/china-news-crawler/scripts/extract_news.py "URL" --format json

# 仅输出 Markdown
uv run .claude/skills/china-news-crawler/scripts/extract_news.py "URL" --format markdown

# 列出支持的平台
uv run .claude/skills/china-news-crawler/scripts/extract_news.py --list-platforms
输出文件

脚本默认输出两种格式到指定目录(默认 ./output):

  • {news_id}.json - 结构化 JSON 数据
  • {news_id}.md - Markdown 格式文章

工作流程

  1. 接收 URL - 用户提供新闻链接
  2. 平台检测 - 自动识别平台类型
  3. 内容提取 - 调用对应爬虫获取并解析内容
  4. 格式转换 - 生成 JSON 和 Markdown
  5. 输出文件 - 保存到指定目录

输出格式

JSON 结构
{
  "title": "文章标题",
  "news_url": "原始链接",
  "news_id": "文章ID",
  "meta_info": {
    "author_name": "作者/来源",
    "author_url": "",
    "publish_time": "2024-01-01 12:00"
  },
  "contents": [
    {"type": "text", "content": "段落文本", "desc": ""},
    {"type": "image", "content": "https://...", "desc": ""},
    {"type": "video", "content": "https://...", "desc": ""}
  ],
  "texts": ["段落1", "段落2"],
  "images": ["图片URL1", "图片URL2"],
  "videos": []
}
Markdown 结构
# 文章标题

## 文章信息
**作者**: xxx
**发布时间**: 2024-01-01 12:00
**原文链接**: [链接](URL)

---

## 正文内容

段落内容...

![图片](URL)

---

## 媒体资源
### 图片 (N)
1. URL1
2. URL2

使用示例

提取微信公众号文章
uv run .claude/skills/china-news-crawler/scripts/extract_news.py \
  "https://mp.weixin.qq.com/s/ebMzDPu2zMT_mRgYgtL6eQ"

输出:

[INFO] Platform detected: wechat (微信公众号)
[INFO] Extracting content...
[INFO] Title: 文章标题
[INFO] Author: 公众号名称
[INFO] Text paragraphs: 15
[INFO] Images: 3
[SUCCESS] Saved: ./output/ebMzDPu2zMT_mRgYgtL6eQ.json
[SUCCESS] Saved: ./output/ebMzDPu2zMT_mRgYgtL6eQ.md
提取今日头条文章
uv run .claude/skills/china-news-crawler/scripts/extract_news.py \
  "https://www.toutiao.com/article/7434425099895210546/"

依赖要求

本 Skill 需要以下 Python 包(通常已在主项目中安装):

  • parsel
  • pydantic
  • requests
  • curl-cffi
  • tenacity
  • demjson3

错误处理

错误类型说明解决方案
无法识别该平台URL 不匹配任何支持的平台检查 URL 是否正确
平台不支持非中国站点本 Skill 仅支持中国新闻站点
提取失败网络错误或页面结构变化重试或检查 URL 有效性

注意事项

  • 仅用于教育和研究目的
  • 不要进行大规模爬取
  • 尊重目标网站的 robots.txt 和服务条款
  • 微信公众号可能需要有效的 Cookie(当前默认配置通常可用)

目录结构

china-news-crawler/
├── SKILL.md                      # [必需] Skill 定义文件
├── references/
│   └── platform-patterns.md      # 平台 URL 模式说明
└── scripts/
    ├── extract_news.py           # CLI 入口脚本
    ├── models.py                 # 数据模型
    ├── detector.py               # 平台检测
    ├── formatter.py              # Markdown 格式化
    └── crawlers/                 # 爬虫模块
        ├── __init__.py
        ├── base.py               # BaseNewsCrawler 基类
        ├── fetchers.py           # HTTP 获取策略
        ├── wechat.py             # 微信公众号
        ├── toutiao.py            # 今日头条
        ├── netease.py            # 网易新闻
        ├── sohu.py               # 搜狐新闻
        └── tencent.py            # 腾讯新闻

参考

Comments

Markdown supported