crw-extract

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

crw-extract — typed JSON from pages

crw-extract — 从网页获取类型化JSON

When to use

适用场景

  • You need a structured JSON object from a page, not prose.
  • Step 6 in the crw ladder. First scrape succeeds (step 2), but you need machine-readable fields. If the source is a local PDF, use crw-parse (step 5) with
    formats:["json"]
    instead.
  • Schema-driven = deterministic output shape. No schema = exploratory; use a
    prompt
    to describe what you want.
  • 你需要从页面获取结构化JSON对象,而非散文式内容。
  • 这是crw工作流阶梯的第6步。当第一步抓取成功(第2步)但你需要机器可读字段时使用。如果数据源是本地PDF,请改用crw-parse(第5步)并设置
    formats:["json"]
  • 基于Schema驱动 = 输出形状确定。无Schema = 探索式提取;使用
    prompt
    描述你想要的内容。

How extraction works in crw

crw中的提取原理

crw has no
/v1/extract
endpoint
(Firecrawl's dedicated extract API). Instead, extraction runs in two ways, both backed by the same LLM pipeline:
PathWhen to useSync?
Per-page:
formats:["json"]
+
jsonSchema
on scrape
Single URL, or inline during a crawlSynchronous
Async multi-URL:
POST /v2/extract
→ poll
GET /v2/extract/{id}
Many URLs, fire-and-forgetAsync
/v2/extract
is marked deprecated in the server (it recommends
/v2/scrape
with
formats:["json"]
), but it works and is useful for multi-URL batches.
Requires a server-side LLM. Set
[extraction.llm]
in the server config (provider, api_key, model). Without it, requests return an error (HTTP 4xx) — e.g. 422 "no LLM configured". Use
crw setup
to configure the LLM for the CLI.
crw没有专门的
/v1/extract
端点
(Firecrawl的专用提取API)。相反,提取通过两种方式运行,均由同一LLM管道提供支持:
方式适用场景是否同步
单页提取:抓取时设置
formats:["json"]
+
jsonSchema
单个URL,或在抓取过程中实时提取同步
异步多URL提取:
POST /v2/extract
→ 轮询
GET /v2/extract/{id}
多个URL,提交后无需等待异步
/v2/extract
在服务器中标记为已弃用(推荐使用带有
formats:["json"]
/v2/scrape
),但它仍可正常工作,且对批量多URL提取很有用。
需要服务器端LLM。在服务器配置中设置
[extraction.llm]
(提供商、api_key、模型)。如果未配置,请求将返回错误(HTTP 4xx)——例如422错误“no LLM configured”。使用
crw setup
为CLI配置LLM。

Quick start

快速开始

CLI — per-page extraction via
--extract
:
bash
undefined
CLI — 通过
--extract
进行单页提取:
bash
undefined

Inline schema

内联Schema

crw scrape "https://example.com/product"
--extract '{"type":"object","properties":{"price":{"type":"number"},"inStock":{"type":"boolean"}}}'
crw scrape "https://example.com/product"
--extract '{"type":"object","properties":{"price":{"type":"number"},"inStock":{"type":"boolean"}}}'

Schema from file

从文件加载Schema

crw scrape "https://example.com/job" --extract @schema.json -o result.json

**MCP** — pass `formats:["json"]` with `jsonSchema` on a scrape:
crw_scrape( url="https://example.com/product", formats=["json"], extract={"schema": {"type":"object","properties":{"price":{"type":"number"}}}} )

Note: the MCP `crw_scrape` accepts `extract.schema` (Firecrawl style). The
REST API also accepts `jsonSchema` as a top-level alias.

**REST** — per-page (synchronous):

```bash
curl -X POST "$CRW_API_URL/v1/scrape" \
  -H "Authorization: Bearer $CRW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/product",
    "formats": ["json"],
    "jsonSchema": {
      "type": "object",
      "properties": {
        "price": {"type": "number"},
        "inStock": {"type": "boolean"}
      }
    }
  }'
REST — async multi-URL (deprecated endpoint, still functional):
bash
undefined
crw scrape "https://example.com/job" --extract @schema.json -o result.json

**MCP** — 在抓取时传入`formats:["json"]`和`jsonSchema`:
crw_scrape( url="https://example.com/product", formats=["json"], extract={"schema": {"type":"object","properties":{"price":{"type":"number"}}}} )

注意:MCP的`crw_scrape`接受`extract.schema`(Firecrawl风格)。REST API也接受`jsonSchema`作为顶级别名。

**REST** — 单页提取(同步):

```bash
curl -X POST "$CRW_API_URL/v1/scrape" \
  -H "Authorization: Bearer $CRW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/product",
    "formats": ["json"],
    "jsonSchema": {
      "type": "object",
      "properties": {
        "price": {"type": "number"},
        "inStock": {"type": "boolean"}
      }
    }
  }'
REST — 异步多URL提取(已弃用端点,仍可使用):
bash
undefined

Start job

启动任务

curl -X POST "$CRW_API_URL/v2/extract"
-H "Authorization: Bearer $CRW_API_KEY"
-H "Content-Type: application/json"
-d '{ "urls": ["https://example.com/p1", "https://example.com/p2"], "schema": {"type":"object","properties":{"price":{"type":"number"}}} }'
curl -X POST "$CRW_API_URL/v2/extract"
-H "Authorization: Bearer $CRW_API_KEY"
-H "Content-Type: application/json"
-d '{ "urls": ["https://example.com/p1", "https://example.com/p2"], "schema": {"type":"object","properties":{"price":{"type":"number"}}} }'

→ {"success":true,"id":"<uuid>","warnings":["...use /v2/scrape..."], ...}

→ {"success":true,"id":"<uuid>","warnings":["...use /v2/scrape..."], ...}

Poll until completed

轮询直到完成

curl "$CRW_API_URL/v2/extract/<uuid>" -H "Authorization: Bearer $CRW_API_KEY"
curl "$CRW_API_URL/v2/extract/<uuid>" -H "Authorization: Bearer $CRW_API_KEY"

→ {"success":true,"status":"completed|scraping|failed","data":{...}}

→ {"success":true,"status":"completed|scraping|failed","data":{...}}

undefined
undefined

Options

选项

NeedCLIMCP / REST
JSON schema
--extract '<schema>'
or
@file.json
jsonSchema
/
extract.schema
Free-text prompt (no schema)
prompt
on
/v2/extract
Save output
-o FILE
write the response yourself
Multi-URL asyncnot available
POST /v2/extract
with
urls:[...]
LLM override
--llm-provider
,
--llm-key
,
--llm-model
server config only
需求CLIMCP / REST
JSON Schema
--extract '<schema>'
@file.json
jsonSchema
/
extract.schema
自由文本提示(无Schema)
/v2/extract
中使用
prompt
保存输出
-o FILE
自行处理响应并写入
多URL异步提取不支持使用带有
urls:[...]
POST /v2/extract
LLM覆盖配置
--llm-provider
,
--llm-key
,
--llm-model
仅支持服务器配置

Tips

提示技巧

  • Schema = deterministic, prompt = exploratory. A schema pins the output shape; a free-text
    prompt
    is useful for exploration but less reliable. Start with a schema when you know the fields you want.
  • Don't over-specify. Narrow schemas ("give me exactly these three fields") extract more reliably than wide ones with fifty optional fields.
  • Crawl + extract in one pass.
    crw_crawl
    accepts a
    jsonSchema
    parameter — each page in the crawl gets extracted against the schema, saving a second round-trip.
  • Check
    data.json
    in the scrape response.
    Per-page extraction lands in
    data.json
    , not
    data.markdown
    . The
    markdown
    field is also populated for reference.
  • Schema确保确定性,提示用于探索。Schema固定输出形状;自由文本
    prompt
    适用于探索但可靠性较低。当你明确需要哪些字段时,优先使用Schema。
  • 不要过度指定Schema。范围狭窄的Schema(“只给我这三个字段”)比包含五十个可选字段的宽泛Schema提取更可靠。
  • 一次完成抓取+提取
    crw_crawl
    接受
    jsonSchema
    参数——抓取中的每个页面都会根据Schema进行提取,节省一次往返请求。
  • 检查抓取响应中的
    data.json
    。单页提取结果会放在
    data.json
    中,而非
    data.markdown
    markdown
    字段也会填充,供参考使用。

See also

相关链接

  • crw-scrape — scrape a page without schema extraction
  • crw-parse — extract structured data from a local PDF
  • crw-best-practices — SDK usage patterns
  • crw — ladder overview
  • crw-scrape — 无需Schema提取的页面抓取
  • crw-parse — 从本地PDF提取结构化数据
  • crw-best-practices — SDK使用模式
  • crw — 工作流阶梯概述