关于 web-content-fetcher
将 URL 网页主体提取为 Markdown 的技能,并保留文档结构。它根据站点情况选择 Scrapling 的快速或 stealth 模式,必要时使用 Jina Reader,并规定失败后的处理方式。
主要功能
- 01将网页内容提取为 Markdown
- 02选择快速或 stealth 抓取
- 03按域名选择抓取模式
- 04限制输出字符数
- 05使用 Jina Reader 作为备用
- 06单次失败后停止尝试
适用场景
- 01将文章 URL 转为 Markdown
- 02抓取 JavaScript 渲染的网页
- 03限制提取文本以适配上下文
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ shirenchuang/ web-content-fetcher --skill web-content-fetcher安装后在 Claude Code 中输入/web-content-fetcher确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
.gitignorerequirements.txtREADME.mdscripts/fetch.py详细介绍
网页内容提取器
给定一个 URL,返回其主要内容,并整理为干净的 Markdown 格式——保留标题、链接、图片、列表、代码块等。
提取策略
每个 URL 始终只尝试一种方法——不要盲目地逐个尝试。提前选好合适的方法。
URL
│
├─ 1. Scrapling script (preferred)
│ Run fetch.py — check the domain routing table to decide fast vs --stealth.
│ Works for most sites. Returns clean Markdown directly.
│
└─ 2. Jina Reader (fallback — only if Scrapling fails or dependencies not installed)
web_fetch("https://r.jina.ai/<url>")
Free tier: 200 req/day. Fast (~1-2s), good Markdown output.
Does NOT work for: WeChat (403), some Chinese platforms.
Scrapling 脚本
python3 <SKILL_DIR>/scripts/fetch.py "<url>" [max_chars] [--stealth]
<SKILL_DIR> 是此 SKILL.md 所在的目录。调用脚本前,请先解析该目录。
脚本内置两种模式:
- 默认模式(快速): HTTP 抓取,约需 1-3 秒,适用于大多数网站
--stealth: 无头浏览器,约需 5-15 秒,适用于使用 JS 渲染或有反抓取机制的网站
不使用 --stealth 运行时,如果快速模式获取的内容太少,脚本会自动回退到 stealth 模式。因此通常无需手动指定 --stealth——只有当你已知网站需要该模式时,才强制使用它(参见路由表);这样可以省去最初的快速尝试。
域名路由
首次调用时,使用此表选择合适的模式:
| 域名 | 命令 | 原因 |
|---|---|---|
mp.weixin.qq.com | fetch.py <url> --stealth | JS 渲染的内容 |
zhuanlan.zhihu.com | fetch.py <url> --stealth | 反抓取机制 + JS |
juejin.cn | fetch.py <url> --stealth | JS 渲染的 SPA |
sspai.com | fetch.py <url> | 静态 HTML |
blog.csdn.net | fetch.py <url> | 静态 HTML |
ruanyifeng.com | fetch.py <url> | 静态博客 |
openai.com | fetch.py <url> | 静态 HTML |
blog.google | fetch.py <url> | 静态 HTML |
| 其他所有网站 | fetch.py <url> | 自动回退机制会处理 |
脚本选项
# Basic — auto-selects fast or stealth
python3 <SKILL_DIR>/scripts/fetch.py "https://sspai.com/post/73145"
# Force stealth for known JS-heavy sites
python3 <SKILL_DIR>/scripts/fetch.py "https://mp.weixin.qq.com/s/xxx" --stealth
# Limit output to 15000 characters (default: 30000)
python3 <SKILL_DIR>/scripts/fetch.py "https://example.com/article" 15000
# JSON output with metadata (url, mode, selector, content_length)
python3 <SKILL_DIR>/scripts/fetch.py "https://example.com" --json
安装依赖
仅首次使用时需要——脚本会检查并告知是否缺少依赖:
pip install scrapling html2text
如果使用系统管理的 Python(macOS/Linux),请添加 --break-system-packages 或使用 venv。
失败规则
- 同一个 URL 失败一次后 → 放弃,并告知用户“无法从此 URL 提取内容”
- 不要重试——每次失败的调用都会浪费上下文令牌
评论
支持 Markdown