news-extractor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNews Extractor Skill
新闻提取Skill
从主流新闻平台提取文章内容,输出 JSON 和 Markdown 格式。
独立可迁移:本 Skill 包含所有必需代码,无外部依赖,可直接复制到其他项目使用。
从主流新闻平台提取文章内容,输出JSON和Markdown格式。
独立可迁移:本Skill包含所有必需代码,无外部依赖,可直接复制到其他项目中使用。
支持平台 (12)
支持平台 (12)
中文平台
中文平台
| 平台 | ID | URL 示例 |
|---|---|---|
| 微信公众号 | | |
| 今日头条 | toutiao | |
| 网易新闻 | netease | |
| 搜狐新闻 | sohu | |
| 腾讯新闻 | tencent | |
| 平台 | ID | URL 示例 |
|---|---|---|
| 微信公众号 | | |
| 今日头条 | toutiao | |
| 网易新闻 | netease | |
| 搜狐新闻 | sohu | |
| 腾讯新闻 | tencent | |
国际平台
国际平台
| 平台 | ID | URL 示例 |
|---|---|---|
| BBC News | bbc | |
| CNN News | cnn | |
| Twitter/X | | |
| Lenny's Newsletter | lenny | |
| Naver Blog | naver | |
| Detik News | detik | |
| Quora | quora | |
| 平台 | ID | URL 示例 |
|---|---|---|
| BBC News | bbc | |
| CNN News | cnn | |
| Twitter/X | | |
| Lenny's Newsletter | lenny | |
| Naver Blog | naver | |
| Detik News | detik | |
| Quora | quora | |
依赖安装
依赖安装
本 skill 使用 uv 管理依赖。首次使用前需要安装:
bash
cd .claude/skills/news-extractor
uv sync重要: 所有脚本必须使用 执行,不要直接用 运行。
uv runpython本Skill使用uv管理依赖。首次使用前需执行以下安装步骤:
bash
cd .claude/skills/news-extractor
uv sync重要: 所有脚本必须使用 执行,不要直接用 运行。
uv runpython依赖列表
依赖列表
| 包名 | 用途 |
|---|---|
| pydantic | 数据模型验证 |
| requests | HTTP 请求 |
| curl_cffi | 浏览器模拟抓取 |
| tenacity | 重试机制 |
| parsel | HTML/XPath 解析 |
| demjson3 | 非标准 JSON 解析 |
| 包名 | 用途 |
|---|---|
| pydantic | 数据模型验证 |
| requests | HTTP 请求 |
| curl_cffi | 浏览器模拟抓取 |
| tenacity | 重试机制 |
| parsel | HTML/XPath 解析 |
| demjson3 | 非标准 JSON 解析 |
使用方式
使用方式
基本用法
基本用法
bash
undefinedbash
undefined提取新闻,自动检测平台,输出 JSON + Markdown
提取新闻,自动检测平台,输出JSON+Markdown
uv run .claude/skills/news-extractor/scripts/extract_news.py "URL"
uv run .claude/skills/news-extractor/scripts/extract_news.py "URL"
指定输出目录
指定输出目录
uv run .claude/skills/news-extractor/scripts/extract_news.py "URL" --output ./output
uv run .claude/skills/news-extractor/scripts/extract_news.py "URL" --output ./output
仅输出 JSON
仅输出JSON
uv run .claude/skills/news-extractor/scripts/extract_news.py "URL" --format json
uv run .claude/skills/news-extractor/scripts/extract_news.py "URL" --format json
仅输出 Markdown
仅输出Markdown
uv run .claude/skills/news-extractor/scripts/extract_news.py "URL" --format markdown
uv run .claude/skills/news-extractor/scripts/extract_news.py "URL" --format markdown
Twitter 受保护推文 (需要 Cookie)
Twitter 受保护推文 (需要 Cookie)
uv run .claude/skills/news-extractor/scripts/extract_news.py "URL" --cookie "auth_token=xxx; ct0=yyy"
uv run .claude/skills/news-extractor/scripts/extract_news.py "URL" --cookie "auth_token=xxx; ct0=yyy"
列出支持的平台
列出支持的平台
uv run .claude/skills/news-extractor/scripts/extract_news.py --list-platforms
undefineduv run .claude/skills/news-extractor/scripts/extract_news.py --list-platforms
undefined输出文件
输出文件
脚本默认输出两种格式到指定目录(默认 ):
./output- - 结构化 JSON 数据
{news_id}.json - - Markdown 格式文章
{news_id}.md
脚本默认输出两种格式到指定目录(默认 ):
./output- - 结构化JSON数据
{news_id}.json - - Markdown格式文章
{news_id}.md
工作流程
工作流程
- 接收 URL - 用户提供新闻链接
- 平台检测 - 自动识别平台类型
- 内容提取 - 调用对应爬虫获取并解析内容
- 格式转换 - 生成 JSON 和 Markdown
- 输出文件 - 保存到指定目录
- 接收 URL - 用户提供新闻链接
- 平台检测 - 自动识别平台类型
- 内容提取 - 调用对应爬虫获取并解析内容
- 格式转换 - 生成JSON和Markdown
- 输出文件 - 保存到指定目录
输出格式
输出格式
JSON 结构
JSON 结构
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": []
}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 结构
Markdown 结构
markdown
undefinedmarkdown
undefined文章标题
文章标题
文章信息
文章信息
作者: xxx
发布时间: 2024-01-01 12:00
原文链接: 链接
作者: xxx
发布时间: 2024-01-01 12:00
原文链接: 链接
正文内容
正文内容
段落内容...
段落内容...
媒体资源
媒体资源
图片 (N)
图片 (N)
- URL1
- URL2
undefined- URL1
- URL2
undefined使用示例
使用示例
提取微信公众号文章
提取微信公众号文章
bash
uv run .claude/skills/news-extractor/scripts/extract_news.py \
"https://mp.weixin.qq.com/s/ebMzDPu2zMT_mRgYgtL6eQ"bash
uv run .claude/skills/news-extractor/scripts/extract_news.py \
"https://mp.weixin.qq.com/s/ebMzDPu2zMT_mRgYgtL6eQ"提取 BBC 新闻
提取BBC新闻
bash
uv run .claude/skills/news-extractor/scripts/extract_news.py \
"https://www.bbc.com/news/articles/c797qlx93j0o"bash
uv run .claude/skills/news-extractor/scripts/extract_news.py \
"https://www.bbc.com/news/articles/c797qlx93j0o"提取 Twitter 推文
提取Twitter推文
bash
undefinedbash
undefined公开推文 (无需认证)
公开推文 (无需认证)
uv run .claude/skills/news-extractor/scripts/extract_news.py
"https://x.com/BarackObama/status/896523232098078720"
"https://x.com/BarackObama/status/896523232098078720"
uv run .claude/skills/news-extractor/scripts/extract_news.py
"https://x.com/BarackObama/status/896523232098078720"
"https://x.com/BarackObama/status/896523232098078720"
受保护推文 (需要 Cookie)
受保护推文 (需要Cookie)
uv run .claude/skills/news-extractor/scripts/extract_news.py
"https://x.com/user/status/123456" --cookie "auth_token=xxx; ct0=yyy"
"https://x.com/user/status/123456" --cookie "auth_token=xxx; ct0=yyy"
undefineduv run .claude/skills/news-extractor/scripts/extract_news.py
"https://x.com/user/status/123456" --cookie "auth_token=xxx; ct0=yyy"
"https://x.com/user/status/123456" --cookie "auth_token=xxx; ct0=yyy"
undefined错误处理
错误处理
| 错误类型 | 说明 | 解决方案 |
|---|---|---|
| URL 不匹配任何支持的平台 | 检查 URL 是否正确 |
| 非支持的站点 | 本 Skill 仅支持列出的 12 个平台 |
| 网络错误或页面结构变化 | 重试或检查 URL 有效性 |
| Twitter Cookie 无效 | 重新获取 Cookie |
| 错误类型 | 说明 | 解决方案 |
|---|---|---|
| URL不匹配任何支持的平台 | 检查URL是否正确 |
| 非支持的站点 | 本Skill仅支持列出的12个平台 |
| 网络错误或页面结构变化 | 重试或检查URL有效性 |
| Twitter Cookie无效 | 重新获取Cookie |
注意事项
注意事项
- 仅用于教育和研究目的
- 不要进行大规模爬取
- 尊重目标网站的 robots.txt 和服务条款
- 微信公众号可能需要有效的 Cookie(当前默认配置通常可用)
- Twitter 公开推文无需认证,受保护推文需要 Cookie
- 仅用于教育和研究目的
- 不要进行大规模爬取
- 尊重目标网站的robots.txt和服务条款
- 微信公众号可能需要有效的Cookie(当前默认配置通常可用)
- Twitter公开推文无需认证,受保护推文需要Cookie
目录结构
目录结构
news-extractor/
├── SKILL.md # [必需] Skill 定义文件
├── pyproject.toml # 依赖管理
├── 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 # 腾讯新闻
├── bbc.py # BBC News
├── cnn.py # CNN News
├── twitter.py # Twitter/X
├── twitter_client.py # Twitter API 客户端
├── twitter_types.py # Twitter 数据类型
├── lenny.py # Lenny's Newsletter
├── naver.py # Naver Blog
├── detik.py # Detik News
└── quora.py # Quoranews-extractor/
├── SKILL.md # [必需] Skill 定义文件
├── pyproject.toml # 依赖管理
├── 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 # 腾讯新闻
├── bbc.py # BBC News
├── cnn.py # CNN News
├── twitter.py # Twitter/X
├── twitter_client.py # Twitter API客户端
├── twitter_types.py # Twitter数据类型
├── lenny.py # Lenny's Newsletter
├── naver.py # Naver Blog
├── detik.py # Detik News
└── quora.py # Quora参考
参考
- 平台 URL 模式说明
- 平台URL模式说明