🚀 快速安装

复制以下命令并运行,立即安装此 Skill:

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

💡 提示:需要 Node.js 和 NPM

提取技能

从特定 URL 提取干净内容。当您明确知道需要从哪些页面获取内容时,此工具非常理想。

身份验证

该脚本通过 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-在此处填写您的-api-密钥"
  }
}

快速开始

使用脚本

./scripts/extract.sh '<json>'

示例:

# 单个 URL
./scripts/extract.sh '{"urls": ["https://example.com/article"]}'

# 多个 URL
./scripts/extract.sh '{"urls": ["https://example.com/page1", "https://example.com/page2"]}'

# 带查询焦点和分块
./scripts/extract.sh '{"urls": ["https://example.com/docs"], "query": "authentication API", "chunks_per_source": 3}'

# 针对 JavaScript 页面的高级提取
./scripts/extract.sh '{"urls": ["https://app.example.com"], "extract_depth": "advanced", "timeout": 60}'

基本提取

curl --request POST \
  --url https://api.tavily.com/extract \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "urls": ["https://example.com/article"]
  }'

带查询焦点的多个 URL

curl --request POST \
  --url https://api.tavily.com/extract \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "urls": [
      "https://example.com/ml-healthcare",
      "https://example.com/ai-diagnostics"
    ],
    "query": "AI diagnostic tools accuracy",
    "chunks_per_source": 3
  }'

API 参考

端点

POST https://api.tavily.com/extract

请求头

请求头
Authorization Bearer <TAVILY_API_KEY>
Content-Type application/json

请求体

字段 类型 默认值 描述
urls 数组 必需 要提取的 URL(最多 20 个)
query 字符串 null 根据相关性对内容块重新排序
chunks_per_source 整数 3 每个 URL 返回的内容块数(1-5,需要提供 query)
extract_depth 字符串 "basic" basic(基础)或 advanced(高级,用于 JS 页面)
format 字符串 "markdown" markdowntext(纯文本)
include_images 布尔值 false 是否包含图片 URL
timeout 浮点数 根据情况 最大等待时间(1-60 秒)

响应格式

{
  "results": [
    {
      "url": "https://example.com/article",
      "raw_content": "# 文章标题\n\n内容..."
    }
  ],
  "failed_results": [],
  "response_time": 2.3
}

提取深度

深度 何时使用
basic(基础) 简单的文本提取,速度更快
advanced(高级) 动态/JS 渲染页面、表格、结构化数据

示例

单 URL 提取

curl --request POST \
  --url https://api.tavily.com/extract \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "urls": ["https://docs.python.org/3/tutorial/classes.html"],
    "extract_depth": "basic"
  }'

带查询的定向提取

curl --request POST \
  --url https://api.tavily.com/extract \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "urls": [
      "https://example.com/react-hooks",
      "https://example.com/react-state"
    ],
    "query": "useState and useEffect patterns",
    "chunks_per_source": 2
  }'

JavaScript 密集型页面

curl --request POST \
  --url https://api.tavily.com/extract \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "urls": ["https://app.example.com/dashboard"],
    "extract_depth": "advanced",
    "timeout": 60
  }'

批量提取

curl --request POST \
  --url https://api.tavily.com/extract \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "urls": [
      "https://example.com/page1",
      "https://example.com/page2",
      "https://example.com/page3",
      "https://example.com/page4",
      "https://example.com/page5"
    ],
    "extract_depth": "basic"
  }'

提示

  • 每次请求最多 20 个 URL – 如需更多请分批处理
  • 使用 query + chunks_per_source 仅获取相关内容
  • 先尝试 basic 深度,如果内容缺失再回退到 advanced
  • 为加载缓慢的页面设置更长的 timeout(最长 60 秒)
  • 检查 failed_results 以查看哪些 URL 提取失败

📄 原始文档

完整文档(英文):

https://skills.sh/tavily-ai/skills/extract

💡 提示:点击上方链接查看 skills.sh 原始英文文档,方便对照翻译。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。