AI 工具3 credits
extract_structured
为提取器提供 JSON Schema 和自然语言提示词。LLM 会读取页面并返回符合你 schema 的数据。当未配置 LLM 提供方时,它会使用你的提示回退到 CSS 选择器提取。
使用场景
schema 优先的商品提取
只需定义一次你想要的字段;LLM 会将任意电商站点映射到你的 schema。
简历与文档解析
将候选人姓名、技能和工作经历直接提取到一个类型化对象中。
知识图谱填充
从文章中提取实体和关系,生成供图加载器使用的结构化 JSON。
Endpoint
POST
/api/v1/tools/extract_structuredAuth Required
Free 计划 1 req/s
3 credits
Parameters
LLM 与选择器回退: 提供
llmConfig 以使用 LLM 驱动的提取。不提供时,该工具使用 selectorHints 进行确定性的 CSS 提取 —— 更便宜,且无需 LLM key。| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Required | - | 要从中提取数据的 URL Example: https://example.com/product/123 |
schema | object | Required | - | 描述要提取数据的 JSON Schema Example: {"type":"object","properties":{"title":{"type":"string"},"price":{"type":"number"}},"required":["title"]} |
prompt | string | Optional | - | 指导 LLM 提取的自然语言指令 Example: Extract the product name, current price, and whether it is in stock |
llmConfig | object | Optional | - | 可选的 LLM 提供方配置(provider、apiKey)。省略则使用 CSS 选择器回退。 Example: {"provider": "openai", "apiKey": "sk-..."} |
selectorHints | object | Optional | - | 用于指导提取的 CSS 选择器提示(也供选择器回退使用) Example: {"title": "h1.product-title", "price": ".price"} |
fallbackToSelectors | boolean | Optional | true | 当 LLM 不可用时回退到 CSS 选择器提取 Example: true |
respect_robots | boolean | Optional | true | 遵守目标站点的 robots.txt。保持 `true` 时,robots.txt 对 `CrawlForge` 禁止的路径会在抓取之前以 403 拒绝,且不扣除 credits。仅在你与目标站点另有约定时才设为 `false`——此时响应会带上一条 `warnings`,并且该覆盖会记录到你的 API key 上。 Example: true |
请求示例
cURL — LLM 提取
terminalBash
curl -X POST https://crawlforge.dev/api/v1/tools/extract_structured \
-H "X-API-Key: cf_test_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/product/123",
"schema": {
"type": "object",
"properties": {
"title": { "type": "string" },
"price": { "type": "number" },
"in_stock": { "type": "boolean" }
},
"required": ["title", "price"]
},
"prompt": "Extract the product name, price in USD, and availability",
"llmConfig": { "provider": "openai", "apiKey": "sk-..." }
}'TypeScript — 选择器回退
extractStructured.tsTypescript
const response = await fetch('https://crawlforge.dev/api/v1/tools/extract_structured', {
method: 'POST',
headers: {
'X-API-Key': process.env.CRAWLFORGE_API_KEY!,
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: 'https://example.com/product/123',
schema: {
type: 'object',
properties: {
title: { type: 'string' },
price: { type: 'number' },
},
required: ['title'],
},
selectorHints: {
title: 'h1.product-title',
price: '.price-value',
},
fallbackToSelectors: true,
}),
});
const data = await response.json();
if (data.success) {
console.log(data.data.extracted.title, data.data.extracted.price);
}Python
extract_structured.pyPython
import requests, os
response = requests.post(
'https://crawlforge.dev/api/v1/tools/extract_structured',
headers={
'X-API-Key': os.environ['CRAWLFORGE_API_KEY'],
'Content-Type': 'application/json',
},
json={
'url': 'https://example.com/article/42',
'schema': {
'type': 'object',
'properties': {
'headline': {'type': 'string'},
'author': {'type': 'string'},
'published_at': {'type': 'string'},
'tags': {'type': 'array'},
},
'required': ['headline'],
},
'prompt': 'Extract headline, author, publish date (ISO 8601), and tags',
},
)
data = response.json()
if data['success']:
print(data['data']['extracted'])响应示例
200 OK1.2s
{ "success": true, "data": { "url": "https://example.com/product/123", "data": { "title": "Premium Wireless Headphones", "price": 299.99, "in_stock": true }, "extraction": { "method_by_field": { "title": "selector", "price": "json-ld", "in_stock": "meta" }, "llm_used": false, "note": "Selector/structured-data extraction; LLM-guided extraction is available via the CrawlForge MCP server" }, "extracted_at": "2026-08-26T14:30:00.000Z" }, "credits_used": 3, "credits_remaining": 997, "processing_time": 1240}Field Descriptions
data.data您的 schema 中每个属性对应一个键,并按声明的类型转换。未能找到的字段为 null。data.extraction.method_by_field每个字段的取值来源:`selector` 来自 selectorHints 条目,`json-ld` 来自结构化数据,`meta` 来自 meta 标签,`none` 表示没有任何匹配。data.extraction.llm_used在托管 REST API 上始终为 false——提取基于选择器与结构化数据,绝非生成式。data.extraction.note重申可在何处使用由 LLM 引导的提取。data.extracted_at本次提取的 ISO 8601 时间戳。错误处理
被 robots.txt 拦截(403 Forbidden)
目标站点的 robots.txt 对 CrawlForge 禁止了该路径。若你与目标站点另有约定,可设置 respect_robots: false 予以覆盖——该覆盖会记录到你的 API key 上。该覆盖不适用于列入 CrawlForge 永久排除名单的主机——无论 respect_robots 取何值,这类主机一律被拒绝。
credit 费用
3 credits
每次请求 3 credits
无论本次调用使用 LLM 还是选择器回退,均固定 3 credits。
提示: 当你已有稳定的选择器、无需 LLM 灵活性时,可搭配 scrape_structured(2 credits,仅 CSS)使用。
相关工具
准备好提取类型化结构化数据了吗?免费注册,获取 1,000 credits。