mcpField
F
firecrawl-scrape

firecrawl-scrape

官方
firecrawl营销与增长67483.7k 次安装1 天前更新
代码仓库

关于 firecrawl-scrape

firecrawl-scrape 是从已知 URL 提取内容或执行指定提供方工具的技能。它支持 Markdown 和基于 schema 的 JSON 输出、并发抓取多个 URL,以及处理较大 URL 列表的批量任务。

主要功能

  1. 01将 URL 内容抓取为 Markdown
  2. 02使用 JSON schema 提取字段
  3. 03并发抓取多个 URL
  4. 04运行 batch-scrape 任务
  5. 05查看提供方工具契约

适用场景

  1. 01读取已知网页用于研究
  2. 02从网页提取结构化字段
  3. 03在单个任务中处理一组 URL

安装

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

$npx skills add https://github.com/firecrawl/cli --skill firecrawl-scrape

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

附带文件references/large-results.md

详细介绍

firecrawl scrape

读取 URL 的页面内容,或执行选定的提供方工具以获取结构化数据。使用 search 发现工具,并在执行前使用 list 检查其输入。可以并发抓取多个 URL。

对于结构化数据集,请先使用 搜索技能 查找合适的工作流或数据提供方。直接读取已知页面;复用选定的契约,而不是重复发现。

快速开始

# Basic markdown extraction
firecrawl scrape "<url>" -o .firecrawl/page.md

# Main content only, no nav/footer
firecrawl scrape "<url>" --only-main-content -o .firecrawl/page.md

# Wait for JS to render, then scrape
firecrawl scrape "<url>" --wait-for 3000 -o .firecrawl/page.md

# A few URLs (markdown only; each saved to .firecrawl/; -o is ignored)
firecrawl scrape https://example.com https://example.com/blog https://example.com/docs

# Get markdown and links together
firecrawl scrape "<url>" --format markdown,links -o .firecrawl/page.json

# Ask a question about the page
firecrawl scrape "https://example.com/pricing" --query "What is the enterprise plan price?"

运行 firecrawl scrape --help 查看完整选项列表。

**完成条件:**已检查页面内容或提供方结果是否存在错误,并分段查看内容以回答请求。保留来源链接,并说明部分结果。

从页面获取结构化 JSON

传入 JSON 架构并使用 json 格式,即可获取类型化字段,而不是 Markdown:

firecrawl scrape "<url>" --format json \
  --schema '{"type":"object","properties":{"plan":{"type":"string"},"price":{"type":"string"}},"required":["plan"]}' \
  -o .firecrawl/pricing.json

# Large schemas: keep them in a file
firecrawl scrape "<url>" --format json --schema-file schema.json -o .firecrawl/page.json

结果位于输出中的 .json 下。--schema 仅在 --format 包含 json 时适用;使用逗号添加其他格式(--format markdown,json)。对于多个 URL 使用相同架构的情况,请使用下文的 batch-scrape --schema。

抓取多个已知 URL

当需要 Markdown 以外的格式、JSON 提取、webhook,或之后可以检查的任务时,请对一组已知 URL 使用 firecrawl batch-scrape。对于少量 Markdown 页面,请使用上面的多 URL scrape。

# Start a job (prints a job ID), then check it later
firecrawl batch-scrape https://example.com/a https://example.com/b
firecrawl batch-scrape <job-id>

# Wait and save every document as JSON (urls.txt: one URL per line, # comments ok)
firecrawl batch-scrape --urls-file urls.txt --format markdown,links --wait -o .firecrawl/batch.json

# Same extraction for every URL (--schema or --prompt adds the json format)
firecrawl batch-scrape --urls-file urls.txt --wait \
  --schema '{"type":"object","properties":{"title":{"type":"string"}}}' -o .firecrawl/batch.json

结果位于 .data[] 中,每个 URL 对应一个文档,并包含 metadata.sourceURL。添加 --webhook <url> 可接收通知,添加 --ignore-invalid-urls 可跳过无效条目,添加带有任务 ID 的 --cancel 可停止任务。运行 firecrawl batch-scrape --help 查看所有选项。

查找工具、检查输入并获取帮助

使用 CLI 帮助检查支持的选项,不要凭猜测操作:

firecrawl search --help
firecrawl list --help
firecrawl scrape --help

默认情况下,使用 --domain-tools 发现领域工具会返回工具摘要。添加 --tool-detail full 可预先获取完整契约;也可以按下文所示,使用 list 检查某个选定工具。使用 --tool-detail compact 仅查看提供方、能力和描述;然后使用这两个 ID 通过 list 检查。摘要仍为默认选项。如果马上需要多个相关契约,优先选择 full。

对于结构化数据,请搜索任务,检查匹配工具的契约,然后使用其声明的确切输入字段执行:

# Web + domain matching + semantic tools
firecrawl search '<user question>'

# Semantic tools only
firecrawl search alexandria '<user question>'

# Categories → providers → tools → contract
firecrawl list
firecrawl list <category-id> --category
firecrawl list <provider-id>
firecrawl list <provider-id> <capability-id> --pretty

# Execute a tool
firecrawl scrape <provider-id>/<capability-id> --options '<JSON matching the selected contract>'

普通搜索会同时返回网页结果和工具匹配项;search alexandria 仅搜索工具。list <provider> <capability> --pretty 会显示选定的契约;使用 --json 获取机器可读的输出。要逐步浏览,请依次使用 list、list <category> --category,再使用 list <provider>。搜索和 list 不会执行选定的提供方工具。只读取任务所需的契约;使用返回的标识符,不要自行猜测。

在构建输入或解析结果之前,请先阅读展开后的契约:

  • required: true 表示必须提供该输入;每个 requiresOneOf 组至少需要提供一个成员,但不必全部提供。
  • 检查选定契约时已请求示例。若存在,请阅读单数形式的 example.request 和 example.response;对于输入可选的工具,空请求也可能有效。
  • response.key 标识 data.alexandria[i].data 中的记录字段;空键表示该数据对象本身。不要假设每个提供方都返回 records。
  • 提供方的分页方式与目录的 next 不同:使用契约中的续页输入以及返回的页面或游标,保留筛选条件,并在收到耗尽信号时停止。仅有 paginated: true 并不能说明如何映射这些字段。

执行与大型结果

URL 抓取不会自动执行提供方工具。请使用准确的已发现输入字段,并通过查找工具解析记录 ID,而不要凭空编造。检查每个 data.alexandria[] 结果是否有错误,而不只是查看外层的成功标志。

如果客户端报告输出或上下文限制,上游请求可能已经成功。保留请求 ID 或抓取 ID,并在重复调用提供方之前恢复保留的结果。对于大型数据集和 PDF,如果本地文件系统可用,请使用 --json -o 保存输出,并用 jq 或其他文件工具检查限定范围的片段。将 stderr 与 JSON stdout 分开;通过管道传给 JSON 解析器时,不要使用 2>&1 合并流。若更适合远程处理,请使用 firecrawl scrape firecrawl/bash 从保留的结果中进行选择。有关 ID、命令示例、过期时间和错误,请阅读 大型结果恢复。这是显式恢复,不是自动溢出检测。

PDF 与页数限制

解析 PDF 每页消耗 1 个点数。使用 --max-pages(取值为 1 到 10000 的整数)限制 PDF 解析,尤其是对于大型或未知文档:

firecrawl scrape "https://example.com/report.pdf" --max-pages 5 --json -o .firecrawl/report.json

该上限针对每个 PDF,而非整个命令或总点数。额外格式和选项可能会增加费用。CLI 不会在执行前估算页数或费用。使用 JSON 输出检查返回的 metadata.numPages(已解析页数)、metadata.totalPages(文档总页数)以及存在时的 metadata.creditsUsed;解析页数较少意味着结果不完整。

提示

  • 优先使用普通抓取,而非 --query。 抓取到文件中,然后使用 grep、head,或直接阅读 Markdown——你可以自行搜索并分析完整内容。仅在需要单个特定答案且不保存页面时使用 --query(额外消耗 5 个点数)。
  • 抓取支持静态页面和 JS 渲染的 SPA。 如果页面需要交互(点击、填写表单、翻页),或抓取遗漏了内容,请改用 interact。
  • 多个 URL 会并发抓取——使用 firecrawl --status 查看并发限制。此模式仅保存 Markdown,并忽略 -o;其他请求的格式会被舍弃。如果未请求 Markdown,整个 JSON 响应会写入 .md 文件。需要其他格式或 JSON 提取时,请使用 batch-scrape。
  • 单一格式输出原始内容。多种格式(例如 --format markdown,links)会输出 JSON。
  • 始终为 URL 加引号——Shell 会将 ? 和 & 视为特殊字符。
  • 命名约定:.firecrawl/{site}-{path}.md

另请参阅

评论

支持 Markdown