抓取任意网站并保存为本地markdown文件。适用于下载文档、知识库或网页内容以供离线访问或分析。无需编码,只需提供URL。
Crawl Skill.是一项面向实际任务的技能,主要用于Crawl网站从多个页面提取内容. 理想用于文档、知识库和全站内容提取.;Previewsites.;
该技能适合需要稳定复用相关能力的场景,可作为自动化工作流的一部分,也便于后续检查、调整和扩展。从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;
若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
爬取网站以从多个页面中提取内容。适用于文档站点、知识库及全站范围的内容采集。
需配置 Tavily API Key —— 请前往 https://tavily.com 获取您的密钥
将其添加至 ~/.claude/settings.json 文件中:
{
"env": {
"TAVILY_API_KEY": "tvly-your-api-key-here"
}
}
./scripts/crawl.sh '' [output_dir]
示例:
# 基础爬取
./scripts/crawl.sh '{"url": "https://docs.example.com"}'
# 深度爬取并设置限制
./scripts/crawl.sh '{"url": "https://docs.example.com", "max_depth": 2, "limit": 50}'
# 保存为文件
./scripts/crawl.sh '{"url": "https://docs.example.com", "max_depth": 2}' ./docs
# 聚焦式爬取(含路径过滤)
./scripts/crawl.sh '{"url": "https://example.com", "max_depth": 2, "select_paths": ["/docs/.*", "/api/.*"], "exclude_paths": ["/blog/.*"]}'
# 带语义指令的爬取(适用于 agentic 场景)
./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/.*"]
}'
POST https://api.tavily.com/crawl
| 请求头 | 值 |
|---|---|
Authorization |
Bearer |
Content-Type |
application/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 TitlennContent..."
}
],
"response_time": 12.5
}
| 深度 | 典型页面数 | 耗时 |
|---|---|---|
| 1 | 10–50 | 秒级 |
| 2 | 50–500 | 分钟级 |
| 3 | 500–5000 | 多分钟 |
建议从 max_depth=1 开始,仅在必要时逐步提升深度。
面向 agentic 场景(将结果注入 LLM 上下文):务必同时使用 instructions 和 chunks_per_source。该模式仅返回相关文本块而非整页内容,可避免上下文窗口溢出。
面向数据采集(保存至本地文件):省略 chunks_per_source,以获取完整页面内容。
适用于将爬取结果作为上下文输入给 LLM 的场景:
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 文件。
若仅需获取 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"
]
}
chunks_per_source —— 可防止将结果喂给 LLM 时引发上下文爆炸chunks_per_source —— 即明确需要保存完整页面内容至文件时max_depth=1、limit=20),再根据需要逐步扩大规模limit,防止失控爬取相关专题
热门下载
相关下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 134.1万人学习
共49课时 | 82.5万人学习
最新文章