SuperAPI AI 工具集

flarecrawl-extraction

数据与分析

查看项目

更新于 10-15 11:08

技能介绍

用途

Flarecrawl Extraction 用于从网页中提取结构化数据。它借助 Cloudflare Workers AI,通过自然语言提示词(prompt)描述需要抽取的内容,并可选用 JSON Schema 约束输出结构,最终得到结构化 JSON。

主要能力

  • 基础提取:用自然语言描述要抽取的字段,例如产品名称与价格。
  • JSON Schema 约束:通过 --schema 内联传入 schema,或通过 --schema-file 指定 schema 文件,描述期望的输出形状。
  • 多 URL 顺序提取:--urls 接受逗号分隔的多个 URL,顺序执行。
  • 批量并行提取:--batch 指定 URL 列表文件,--workers 指定并行数,输出为 NDJSON,每行包含 {index, status, data/error}。
  • 与 scrape --format json 的区别:extract 支持自定义提示词与 JSON Schema,适合抽取特定字段;scrape --format json 使用通用“提取主要内容”逻辑,不支持自定义提示词与 schema,适合快速内容提取。两者都支持批量模式。
  • MCP 等价能力:extract_data(urls, prompt, json_schema) 复合工具通过 flarecrawl MCP 服务器暴露,MCP 设置参见 flarecrawl-ops 技能。

使用方式

基础提取:

flarecrawl extract "Get all product names and prices" --urls https://shop.example.com --json

带 JSON Schema:

flarecrawl extract "Extract article metadata" --urls https://blog.example.com \
  --schema '{"type":"json_schema","schema":{"type":"object","properties":{"title":{"type":"string"},"date":{"type":"string"},"author":{"type":"string"}}}}'

从文件读取 schema:

flarecrawl extract "Extract data" --urls https://example.com --schema-file schema.json

多 URL(顺序):

flarecrawl extract "Get page title" --urls https://a.com,https://b.com --json

批量提取(并行):

flarecrawl extract "Get page title and description" --batch urls.txt --workers 5
# Output: NDJSON with {index, status, data/error}

工作流示例

Schema 驱动的提取:

  1. 定义描述期望输出形状的 JSON schema。
  2. 编写清晰的提示词描述要提取的内容。
  3. 使用 --schema 或 --schema-file 运行提取。
# schema.json
cat > schema.json << 'EOF'
{
  "type": "json_schema",
  "schema": {
    "type": "object",
    "properties": {
      "products": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "name": {"type": "string"},
            "price": {"type": "number"},
            "currency": {"type": "string"}
          }
        }
      }
    }
  }
}
EOF

flarecrawl extract "Extract all products with their prices" \
  --urls https://shop.example.com --schema-file schema.json --json

批量提取流水线:

# 1. Discover pages
flarecrawl map https://shop.example.com --json | jq -r '.data[]' | grep '/product/' > products.txt

# 2. Batch extract with schema
flarecrawl extract "Get product name, price, and description" \
  --batch products.txt --workers 5 --schema-file schema.json

# 3. Filter successful results
flarecrawl extract "Get product name and price" --batch products.txt \
  | jq 'select(.status == "ok") | .data'

高级用法

--body 绕过:用于未以 flag 形式暴露的高级 Workers AI 选项:

flarecrawl extract --body '{"url":"https://example.com","prompt":"Extract data","response_format":{"type":"json_schema","schema":{...}}}' --json

适用场景

  • 需要从网页抽取特定字段(如产品名称、价格、文章元数据)时使用 extract。
  • 需要通用内容提取时使用 scrape --format json。
  • 需要批量处理大量 URL 时使用 --batch 与 --workers 并行提取。

限制与注意事项

  • Workers AI 模型存在上下文限制,非常大的页面可能被截断。
  • 提示词质量很重要,需明确指定想要的字段。
  • Schema 校验是尽力而为,Workers AI 可能无法完美匹配复杂 schema。
  • 无流式输出,提取需等待完整 AI 响应。
  • 成本:$0 —— Workers AI 提取包含在 Browser Rendering 定价中。
  • 批量输出为 NDJSON,而非 {data, meta} 信封格式,需逐行解析。
  • 可组合 --urls 与 --batch,批量 URL 会补充 --urls 逗号列表。