跳到主要内容

接口参考:单页抽取

POST /api/v2/extract​

抓取一个公开 URL,抽取 11 个文章字段,写入系统托管默认文章库。

scope:task:write

请求头​

头必填说明
Idempotency-Key否建议带;不带时靠 URL 去重;幂等寿命 120 秒

请求体​

字段类型必填默认说明
urlstring是-http/https,≤2048
refreshboolean否false内容变化时是否写新版本
formatstring否jsonjson / md / text
fieldsstring[]否全部只允许 11 个固定字段
contentMaxCharsinteger否200001000~200000

11 个字段:title、content、pubDate、author、category、tag、 description、keywords、source、summary、images。

响应 data​

{
"taskId": 738590,
"record": {
"_id": 1024,
"_url": "https://doc.keydatas.com/getting-started/wangzhan-wenzhang-caiji.html",
"_createdAt": 1760000000000,
"_updatedAt": 1760000000000,
"title": "文章标题",
"content": "正文纯文本……",
"tag": ["标签"],
"keywords": ["关键词"],
"images": ["https://example.com/a.jpg"],
"_warnings": []
},
"markdown": "# 文章标题\n\n正文……",
"text": null,
"deduped": false,
"refreshed": false,
"tokenEstimate": 3200,
"elapsedMs": 1840,
"warnings": []
}

format=md 时正文在 markdown;format=text 时在 text。 非 json 格式下 record 不含 content。

幂等​

情况结果
首次写新记录,deduped=false
内容未变返回已有记录,deduped=true
内容变化 + refresh=false返回旧记录,deduped=true,warning content_changed
内容变化 + refresh=true写新版本,refreshed=true
同 URL 并发409 extract_in_progress

错误​

HTTPcode场景
400invalid_paramurl 缺失/超长、fields 含未知字段
401unauthorizedKey 无效
403extract_disabled套餐未开放或服务端关闭
409extract_in_progress同 URL 正在处理
409default_task_initializing默认文章库正在创建
422invalid_url内网/回环/非 http(s)/云元数据
422content_unavailable无正文
422unsupported_content_type非 HTML
422html_too_largeHTML 超过 2MB
429quota_exceeded当日配额用完
429extract_busy平台并发已满
502fetch_failed抓取失败
503extract_capacity平台日上限
503quota_unavailable配额服务不可用
504extract_timeout30 秒预算用尽
500persist_failed落库失败

示例​

curl -X POST https://open.keydatas.com/api/v2/extract \
-H "Authorization: Bearer $KEYDATAS_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"url":"https://doc.keydatas.com/getting-started/wangzhan-wenzhang-caiji.html","format":"md","contentMaxChars":8000}'

相关​