WebFetch API参考
Dump DOM
获取 HTML、检查渲染结果,并复用 DOM 快照。
POST /v1/dom/dump
当你需要直接拿到抓取后的 HTML、检查页面渲染结果、或者希望在后续提取请求中复用 DOM 快照时,使用这个接口。
鉴权说明
- 当前接口处于内测阶段
- 外部调用时,请求需要带
X-API-Key - 请联系管理员获取 API key
请求体
{
"url": "https://example.com",
"options": {
"engine_preference": "lightmount_dcl",
"timeout_ms": 30000,
"filter_scripts_styles": false
}
}字段说明
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
url | string | 是 | 要抓取的页面 URL |
options.engine_preference | string | 否 | 指定引擎,默认 auto |
options.timeout_ms | int | 否 | 请求超时 |
options.filter_scripts_styles | bool | 否 | 是否在返回和落盘前移除 script 和 style |
支持的 engine_preference:
autohttpchromechrome_cdplightmount_litelightmount_dcllightmount_domstable
基础示例
API_KEY='<your-api-key>'
curl -sS -X POST https://webfetch.lexmount.com/v1/dom/dump \
-H 'content-type: application/json' \
-H "X-API-Key: $API_KEY" \
-d '{
"url": "https://example.com",
"options": {
"engine_preference": "lightmount_dcl",
"timeout_ms": 30000
}
}' \
| jq '{final_url, engine, dom_id, dump_path, html_len:(.html|length)}'响应字段
常用返回字段:
urlfinal_urlstatus_codefetched_atenginedom_iddump_pathhtmldebug
过滤 script / style
curl -sS -X POST https://webfetch.lexmount.com/v1/dom/dump \
-H 'content-type: application/json' \
-H "X-API-Key: $API_KEY" \
-d '{
"url": "https://example.com",
"options": {
"engine_preference": "lightmount_dcl",
"filter_scripts_styles": true
}
}' \
| jq '{dom_id, has_script:(.html|test("<script"; "i")), has_style:(.html|test("<style"; "i"))}'这个模式适合拿到更干净的 DOM 用于检查和模板调试,但不要把它当成浏览器原始快照的完全等价物。
复用 dom_id
先抓取快照,再把 dom_id 交给 /v1/extract:
DOM_ID="$(curl -sS -X POST https://webfetch.lexmount.com/v1/dom/dump \
-H 'content-type: application/json' \
-H "X-API-Key: $API_KEY" \
-d '{"url":"https://example.com","options":{"engine_preference":"lightmount_dcl"}}' \
| jq -r '.dom_id')"
curl -sS -X POST https://webfetch.lexmount.com/v1/extract \
-H 'content-type: application/json' \
-H "X-API-Key: $API_KEY" \
-d "{\"extract\":{\"dom_id\":\"$DOM_ID\"},\"trace\":{\"include_steps\":false,\"include_raw_dom\":false}}" \
| jq '{title:.result.title, engine:.result.engine, template_id:.result.template_id, dom_id:.metadata.dom_id}'如果要排查失败原因,见 Common Errors。
Lexmount 文档