| name | tool-web-fetch |
| description | 本地搜索引擎与网页内容获取工具 - 绕过WebSearch/WebFetch域名限制,支持多API搜索、代理抓取、反爬处理。触发场景:(1) WebSearch被限制 (2) WebFetch无法访问特定域名 (3) 需要获取GitHub等内容 (4) 需要处理反爬网站 |
本地搜索引擎与网页内容获取工具
提供多种方式绕过 WebSearch/WebFetch 的域名限制,获取网页内容。
工作流程
搜索流程:
1. 优先使用 WebSearch 进行搜索
2. 如果 WebSearch 被限制 → 使用备用搜索 API
3. 对于搜索结果中的具体 URL → 尝试 WebFetch
4. 如果 WebFetch 失败 → 使用本工具直接抓取
内容获取流程:
1. 优先尝试 WebFetch
2. 如果域名被限制 → 使用脚本直接请求
3. 如果需要反爬处理 → 使用 web_fetch.py
API 可用性测试结果
✅ 可立即使用的 API
| API | 响应时间 | 用途 | 调用方式 |
|---|
| GitHub Search API | 0.87s | 搜索代码仓库 | scripts/web_fetch.py |
| Stack Overflow API | 0.69s | 技术问答搜索 | 直接 API 调用 |
| Wikipedia API | 0.71s | 百科资料搜索 | 直接 API 调用 |
| Hacker News API | 0.60s | 技术新闻搜索 | 直接 API 调用 |
| DuckDuckGo API | 0.52s | 即时答案摘要 | 直接 API 调用 |
❌ 当前不可用的 API
| API | 错误 | 原因 |
|---|
| SearXNG 公开实例 | 403/连接失败 | 代理环境限制 |
| Reddit API | 403 Forbidden | 需要OAuth认证 |
🔑 需要 API Key 的 API(推荐申请)
一、快速使用指南
1.1 GitHub 搜索与内容获取
python scripts/web_fetch.py "https://api.github.com/search/repositories?q=python+web+framework&sort=stars&per_page=10" --json
python scripts/web_fetch.py "https://api.github.com/repos/owner/repo" --json
python scripts/web_fetch.py "https://raw.githubusercontent.com/owner/repo/main/README.md"
python scripts/web_fetch.py "https://api.github.com/repos/owner/repo/issues?state=open" --json
1.2 Stack Overflow 搜索
python scripts/web_fetch.py "https://api.stackexchange.com/2.3/search?intitle=python+error&site=stackoverflow&sort=votes&pagesize=10" --json
python scripts/web_fetch.py "https://api.stackexchange.com/2.3/questions/{id}?site=stackoverflow&filter=!-*f(6rc.lF" --json
1.3 Wikipedia 搜索
python scripts/web_fetch.py "https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=python&format=json&srlimit=10" --json
python scripts/web_fetch.py "https://zh.wikipedia.org/w/api.php?action=query&list=search&srsearch=人工智能&format=json&srlimit=10" --json
1.4 Hacker News 搜索
python scripts/web_fetch.py "https://hn.algolia.com/api/v1/search?query=python&hitsPerPage=10" --json
二、代理配置
2.1 Clash 代理自动检测
脚本会自动检测以下 Clash 端口:
| Clash 版本 | HTTP 端口 | SOCKS5 端口 |
|---|
| Clash for Windows | 7890 | 7891 |
| Clash Verge | 7897 | 7898 |
| Clash Meta | 7890 | 7891 |
2.2 手动指定代理
python scripts/web_fetch.py "https://api.github.com/repos/user/repo" --proxy http://127.0.0.1:7890
python scripts/web_fetch.py "https://api.github.com/repos/user/repo" --no-proxy
export HTTP_PROXY="http://127.0.0.1:7890"
export HTTPS_PROXY="http://127.0.0.1:7890"
python scripts/web_fetch.py "https://api.github.com/repos/user/repo"
三、脚本使用详解
3.1 web_fetch.py - 网页抓取脚本
python scripts/web_fetch.py "<url>" [--options]
--json
--output, -o
--summary, -s
--proxy, -p
--no-proxy
--user-agent, -u
--cookies, -c
--timeout, -t
3.2 使用示例
python scripts/web_fetch.py \
"https://api.github.com/search/repositories?q=fastapi&sort=stars" \
--json -o search_result.json
python scripts/web_fetch.py \
"https://raw.githubusercontent.com/tiangolo/fastapi/main/README.md" \
--proxy http://127.0.0.1:7897
python scripts/web_fetch.py \
"https://api.stackexchange.com/2.3/questions/123?site=stackoverflow" \
--json
python scripts/web_fetch.py \
"https://example.com/protected-page" \
-u chrome -c "session=abc123; token=xyz"
四、API 直接调用参考
4.1 GitHub API
| 功能 | URL 格式 |
|---|
| 搜索仓库 | https://api.github.com/search/repositories?q={query}&sort=stars&per_page={n} |
| 仓库信息 | https://api.github.com/repos/{owner}/{repo} |
| README 内容 | https://raw.githubusercontent.com/{owner}/{repo}/{branch}/README.md |
| 文件内容 | https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{path} |
| Issues 列表 | https://api.github.com/repos/{owner}/{repo}/issues |
| Releases | https://api.github.com/repos/{owner}/{repo}/releases |
| 用户信息 | https://api.github.com/users/{username} |
4.2 Stack Overflow API
| 功能 | URL 格式 |
|---|
| 搜索问题 | https://api.stackexchange.com/2.3/search?intitle={query}&site=stackoverflow&sort=votes |
| 问题详情 | https://api.stackexchange.com/2.3/questions/{id}?site=stackoverflow |
| 问题答案 | https://api.stackexchange.com/2.3/questions/{id}/answers?site=stackoverflow |
| 标签搜索 | https://api.stackexchange.com/2.3/questions?tagged={tag}&site=stackoverflow |
4.3 Wikipedia API
| 功能 | URL 格式 |
|---|
| 英文搜索 | https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch={query}&format=json |
| 中文搜索 | https://zh.wikipedia.org/w/api.php?action=query&list=search&srsearch={query}&format=json |
| 页面内容 | https://en.wikipedia.org/w/api.php?action=query&titles={title}&prop=extracts&format=json |
4.4 Hacker News API
| 功能 | URL 格式 |
|---|
| 搜索 | https://hn.algolia.com/api/v1/search?query={query}&hitsPerPage={n} |
| 热门帖子 | https://hn.algolia.com/api/v1/search?tags=front_page&hitsPerPage={n} |
| 最新帖子 | https://hn.algolia.com/api/v1/search?tags=story&hitsPerPage={n} |
五、curl 快速抓取
当 Python requests 出现问题时,可直接使用 curl:
5.1 基础抓取
curl -sL "https://api.github.com/repos/user/repo" | python -m json.tool
curl -sL "https://example.com" | head -100
curl -sL "https://example.com" -o output.html
5.2 GitHub 专用
curl -sL "https://raw.githubusercontent.com/owner/repo/main/README.md"
curl -sL "https://api.github.com/search/repositories?q=python&sort=stars&per_page=5"
curl -sL "https://api.github.com/repos/python/cpython" | python -c "
import sys, json, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
d = json.load(sys.stdin)
print(f'仓库: {d[\"full_name\"]}')
print(f'Stars: {d[\"stargazers_count\"]}')
print(f'语言: {d[\"language\"]}')
"
六、反爬处理技巧
6.1 User-Agent 设置
脚本内置多种 User-Agent:
| 名称 | 用途 |
|---|
chrome | 模拟 Chrome 浏览器 |
firefox | 模拟 Firefox 浏览器 |
safari | 模拟 Safari 浏览器 |
googlebot | 模拟 Google 爬虫 |
curl | 简单请求 |
bot | Python requests 默认 |
python scripts/web_fetch.py "https://example.com" -u chrome
python scripts/web_fetch.py "https://example.com" -u "MyBot/1.0"
6.2 Cookie 使用
python scripts/web_fetch.py "https://example.com/private" -c "session=abc123; token=xyz"
python scripts/web_fetch.py "https://example.com/user" -c "$(cat cookies.txt)"
七、完整使用示例
示例 1:搜索 Python Web 框架
场景: 需要搜索 Python Web 框架相关信息
python scripts/web_fetch.py \
"https://api.github.com/search/repositories?q=python+web+framework&sort=stars&per_page=10" \
--json -o github_results.json
python scripts/web_fetch.py \
"https://api.github.com/repos/fastapi/fastapi" \
--json
python scripts/web_fetch.py \
"https://raw.githubusercontent.com/tiangolo/fastapi/main/README.md" \
-o fastapi_readme.md
python scripts/web_fetch.py \
"https://api.stackexchange.com/2.3/search?intitle=fastapi&site=stackoverflow&sort=votes&pagesize=5" \
--json
示例 2:技术调研流程
场景: 调研某个技术主题
python scripts/web_fetch.py "https://api.github.com/search/repositories?q={topic}&sort=stars" --json
python scripts/web_fetch.py "https://hn.algolia.com/api/v1/search?query={topic}" --json
python scripts/web_fetch.py "https://zh.wikipedia.org/w/api.php?action=query&list=search&srsearch={topic}&format=json" --json
python scripts/web_fetch.py "https://api.stackexchange.com/2.3/search?intitle={topic}&site=stackoverflow&sort=votes" --json
示例 3:WebFetch 失败时的替代方案
场景: WebFetch 报错 "domain is blocked"
python scripts/web_fetch.py "https://被限制域名.com/page"
curl -sL -H "User-Agent: Mozilla/5.0" "https://被限制域名.com/page" > output.html
python scripts/web_fetch.py "https://api.github.com/repos/user/repo" --json
八、质量标准
| 标准 | 要求 | 检查方式 |
|---|
| 响应时间 | ≤ 15秒 | 超时设置 |
| 成功率 | ≥ 90% | 多 API 备用 |
| 代理检测 | 自动 | 端口扫描 |
| User-Agent | 必须设置 | Header 检查 |
| 编码处理 | UTF-8 | 自动解码 |
九、依赖工具
| 工具 | 用途 | 安装 |
|---|
| Python 3.8+ | 脚本执行 | 系统自带 |
| requests | HTTP 请求 | pip install requests |
| curl | 备用抓取 | 系统自带 |
十、注意事项
- API 速率限制: GitHub API 未认证限制 60次/小时,Stack Overflow 300次/天
- 代理检测: 脚本自动检测 Clash 代理,也可手动指定
- 合理延迟: 批量请求时添加间隔,避免触发限制
- 优先 WebSearch/WebFetch: 先尝试内置工具,失败后使用本工具
- API Key: 建议申请 Brave Search 或 Serper API Key 以获得更好的搜索体验
相关文档
技能版本: 2.0.0
最后更新: 2026-06-29
创建者: AI Assistant