| name | web-fetch |
| description | 万能网页抓取工具,支持多种策略绕过反爬虫检测。触发词:抓取网页、获取网页内容、scrape。 |
| version | 1 |
Web Fetch - 万能网页抓取工具
版本: v1.0
创建日期: 2026-03-15
核心优势: 多策略自动切换,从轻量到重量级,智能选择最优方案
📋 概述
统一网页抓取工具,支持 4 种抓取策略:
| 方法 | 速度 | 适用场景 | 反爬虫绕过 |
|---|
| curl | ⚡ 最快 | 静态 HTML | ❌ 无 |
| agent-browser | 🚀 快 | 动态 SPA | ✅ 中等 |
| browser-use | 🐢 中 | 复杂交互 | ✅ 强 |
| playwright | 🐌 慢 | 强反爬虫 | ✅✅ 最强 |
自动模式: 从 curl 开始,失败后自动尝试更强的方法
🚀 快速开始
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://example.com"
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://example.com" --method browser-use
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://example.com" --screenshot out.png
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://example.com" --json
📤 命令参数
| 参数 | 说明 | 默认值 |
|---|
--method METHOD | 抓取方法:auto, curl, playwright, all | auto |
--timeout MS | 超时时间(毫秒) | 30000 |
--retry / --no-retry | 是否启用重试 | true |
--output FILE | 保存内容到文件 | - |
--screenshot FILE | 保存截图 | - |
--wait N | 等待 N 秒后获取 | 0 |
--ua UA | 自定义 User-Agent | 随机 |
--json | JSON 输出格式 | false |
--stats | 显示统计报告 | false |
📚 使用示例
1. 快速抓取静态页面
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://github.com/anthropics/claude-code"
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://example.com/article/123" --output article.html
2. 动态 SPA 页面
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://app.example.com" --wait 3 --method playwright
3. 带截图
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://example.com" --screenshot page.png
4. 绕过反爬虫
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://protected-site.com" --method playwright
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://cloudflare-protected.com" --method browser-use
5. JSON 输出(便于程序处理)
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://api.example.com" --json | jq '.content'
🏗️ 架构设计
方法选择流程
用户请求
↓
auto 模式?
├─ 是 → 尝试 curl → 失败 → playwright
└─ 否 → 直接使用指定方法
↓
获取成功?
├─ 是 → 输出结果
└─ 否 → 重试(最多 3 次,指数退避)
方法对比
Curl
✅ 最快(~1 秒)
✅ 无需浏览器
✅ 低资源占用
❌ 无法执行 JS
❌ 无法绕过反爬虫
Playwright
✅ 最强反爬虫绕过
✅ 完整浏览器功能
✅ Stealth 模式隐藏特征
❌ 最慢(~10-20 秒)
❌ 需要安装 playwright
⚙️ 配置选项
环境变量
export WEB_FETCH_UA="Mozilla/5.0 ..."
export WEB_FETCH_TIMEOUT=60000
export WEB_FETCH_METHOD=browser-use
Cookies 管理
🧪 测试
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://example.com" --method curl
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://example.com" --method agent-browser
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://example.com" --method browser-use
node ~/src/user-scripts/skills/web-fetch/scripts/fetch-page.mjs "https://example.com" --method playwright
🐛 故障排查
问题 1:所有方法都失败
curl -I https://example.com
ping example.com
node fetch-page.mjs "url" --ua "Mozilla/5.0 ..."
问题 2:内容为空
node fetch-page.mjs "url" --wait 5
node fetch-page.mjs "url" --method browser-use
问题 3:反爬虫检测
node fetch-page.mjs "url" --method playwright
browser-use --browser real open "url"
问题 4:需要登录
browser-use --browser real open "https://example.com/login"
browser-use cookies export cookies.json
browser-use --browser real --profile "Default" open "https://example.com"
📊 输出格式
标准输出
## 网页内容
**URL**: https://example.com
**标题**: Example Domain
**方法**: curl
**耗时**: 1.23s
---
[网页 HTML 内容]
JSON 输出
{
"success": true,
"url": "https://example.com",
"title": "Example Domain",
"method": "curl",
"content": "<html>...",
"elapsed": 1234
}
🔧 依赖安装
sudo pacman -S curl
cd ~/src/user-scripts/skills/web-fetch
npm install playwright puppeteer-extra puppeteer-extra-plugin-stealth
npx playwright install chromium
📈 性能对比
| 方法 | 平均耗时 | 成功率 | 资源占用 |
|---|
| curl | ~1s | 60% | 低 |
| playwright | ~5-30s | 95% | 高 |
📝 完成标准
触发此 skill 时,任务完成必须满足:
📚 参考资源
最后更新:2026-03-15 | 维护:~/src/user-scripts/skills/web-fetch/