mcpField
C
crawl

crawl

github.com/tavily-ai数据与数据库4913.5k 次安装8 周前更新
代码仓库

关于 crawl

crawl 是用于多页面网站内容提取的技能,面向文档研究和站点内容归档。它通过 Tavily API 按深度、路径和指令控制抓取,并可输出相关内容块或完整页面。

主要功能

  1. 01按层级抓取多页面内容
  2. 02通过自然语言指令聚焦主题
  3. 03按路径模式筛选页面
  4. 04返回相关内容块或全文
  5. 05将页面保存为 Markdown 文件

适用场景

  1. 01提取文档站中的 API 指南
  2. 02为 Agent 研究提供精简网页内容
  3. 03归档博客或网站页面
  4. 04先发现站点 URL 再抓取内容

MCP 相关

通过 Tavily MCP server 使用 OAuth 进行身份验证;也可配置 API key。技能调用 Tavily 的 crawl 和 map 接口。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/tavily-ai/skills --skill crawl

安装后在 Claude Code 中输入/crawl确认已加载。

附带文件scripts/crawl.sh

详细介绍

Crawl 技能

爬取网站,从多个页面提取内容。适用于文档、知识库和全站内容提取。

身份验证

此脚本通过 Tavily MCP 服务使用 OAuth。无需手动设置——首次运行时,脚本会:

  1. 检查 ~/.mcp-auth/ 中是否已有令牌
  2. 如果没有找到,则自动打开浏览器进行 OAuth 身份验证

注意: 你必须拥有现有的 Tavily 账户。OAuth 流程仅支持登录,无法通过此流程创建账户。如果你还没有账户,请先在 tavily.com 注册。

替代方案:API 密钥

如果你更倾向于使用 API 密钥,请前往 https://tavily.com 获取密钥,并将其添加到 ~/.claude/settings.json:

{
  "env": {
    "TAVILY_API_KEY": "tvly-your-api-key-here"
  }
}

快速开始

使用脚本
./scripts/crawl.sh '<json>' [output_dir]

示例:

# Basic crawl
./scripts/crawl.sh '{"url": "https://docs.example.com"}'

# Deeper crawl with limits
./scripts/crawl.sh '{"url": "https://docs.example.com", "max_depth": 2, "limit": 50}'

# Save to files
./scripts/crawl.sh '{"url": "https://docs.example.com", "max_depth": 2}' ./docs

# Focused crawl with path filters
./scripts/crawl.sh '{"url": "https://example.com", "max_depth": 2, "select_paths": ["/docs/.*", "/api/.*"], "exclude_paths": ["/blog/.*"]}'

# With semantic instructions (for agentic use)
./scripts/crawl.sh '{"url": "https://docs.example.com", "instructions": "Find API documentation", "chunks_per_source": 3}'

提供 output_dir 时,每个爬取的页面都会另存为一个 Markdown 文件。

基础爬取
curl --request POST \
  --url https://api.tavily.com/crawl \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "https://docs.example.com",
    "max_depth": 1,
    "limit": 20
  }'
使用指令进行定向爬取
curl --request POST \
  --url https://api.tavily.com/crawl \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "https://docs.example.com",
    "max_depth": 2,
    "instructions": "Find API documentation and code examples",
    "chunks_per_source": 3,
    "select_paths": ["/docs/.*", "/api/.*"]
  }'

API 参考

端点
POST https://api.tavily.com/crawl
请求头
请求头值
AuthorizationBearer <TAVILY_API_KEY>
Content-Typeapplication/json
请求正文
字段类型默认值说明
url字符串必填开始爬取的根 URL
max_depth整数1爬取深度(1-5)
max_breadth整数20每页链接数
limit整数50页面总数上限
instructions字符串null用于指定爬取重点的自然语言指引
chunks_per_source整数3每页的文本块数(1-5,需要提供 instructions)
extract_depth字符串"basic"basic 或 advanced
format字符串"markdown"markdown 或 text
select_paths数组null要包含的正则表达式模式
exclude_paths数组null要排除的正则表达式模式
allow_external布尔值true是否包含外部域名的链接
timeout浮点数150最大等待时间(10-150 秒)
响应格式
{
  "base_url": "https://docs.example.com",
  "results": [
    {
      "url": "https://docs.example.com/page",
      "raw_content": "# Page Title\n\nContent..."
    }
  ],
  "response_time": 12.5
}

深度与性能

深度典型页面数耗时
110-50秒
250-500分钟
3500-5000多分钟

从 max_depth=1 开始,仅在需要时增加深度。

用于上下文还是数据收集

用于 Agent(将结果输入上下文): 始终使用 instructions + chunks_per_source。这样只会返回相关文本块,而非完整页面,从而防止上下文窗口溢出。

用于数据收集(保存到文件): 省略 chunks_per_source,以获取完整页面内容。

示例

用于上下文:Agent 式研究(推荐)

在将爬取结果输入大模型上下文时使用:

curl --request POST \
  --url https://api.tavily.com/crawl \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "https://docs.example.com",
    "max_depth": 2,
    "instructions": "Find API documentation and authentication guides",
    "chunks_per_source": 3
  }'

每个页面仅返回最相关的文本块(每块最多 500 个字符),适合放入上下文而不会造成内容过载。

用于上下文:针对性技术文档
curl --request POST \
  --url https://api.tavily.com/crawl \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "https://example.com",
    "max_depth": 2,
    "instructions": "Find all documentation about authentication and security",
    "chunks_per_source": 3,
    "select_paths": ["/docs/.*", "/api/.*"]
  }'
用于数据收集:完整页面归档

在将内容保存到文件以供后续处理时使用:

curl --request POST \
  --url https://api.tavily.com/crawl \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "https://example.com/blog",
    "max_depth": 2,
    "max_breadth": 50,
    "select_paths": ["/blog/.*"],
    "exclude_paths": ["/blog/tag/.*", "/blog/category/.*"]
  }'

返回完整页面内容——使用脚本的 output_dir 将内容保存为 Markdown 文件。

Map API(URL 发现)

如果只需要 URL 而非内容,请使用 map 代替 crawl:

curl --request POST \
  --url https://api.tavily.com/map \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "https://docs.example.com",
    "max_depth": 2,
    "instructions": "Find all API docs and guides"
  }'

仅返回 URL(比 crawl 更快):

{
  "base_url": "https://docs.example.com",
  "results": [
    "https://docs.example.com/api/auth",
    "https://docs.example.com/guides/quickstart"
  ]
}

提示

  • Agent 工作流始终使用 chunks_per_source——将结果输入大模型时可防止上下文溢出
  • 仅在数据收集时省略 chunks_per_source——即将完整页面保存到文件时
  • 从保守设置开始(max_depth=1、limit=20),再逐步提高
  • 使用路径模式聚焦于相关部分
  • 完整爬取前先使用 Map了解网站结构
  • 始终设置 limit,防止爬取失控

评论

支持 Markdown