web_extract
Extract structured JSON from web pages by defining field schemas, returning targeted field values instead of full-page text for direct storage or analysis.
Instructions
抓取网页并按字段 schema 抽取结构化 JSON(字段级数据,可入库)。
适合需要"数据而非整页正文"的场景:给 URL 和字段规则,直接返回字段值, 而不是一段 compact 文本。抓取链路(分级反爬、登录态、合规)与 web_fetch 一致。
字段规则示例: {"fields": { "title": {"selector": "h1"}, "price": {"selector": ".price", "regex": "(\d+(?:.\d+)?)", "group": 1}, "main_link": {"selector": "a", "type": "attr", "attr": "href", "abs_url": true}, "link_count": {"selector": "a", "type": "count"}, "tags": {"selector": ".tag", "type": "list", "list_key": "text"}, "items": {"selector": ".item", "type": "list", "fields": { "name": {"selector": ".name"}, "url": {"selector": "a", "type": "attr", "attr": "href", "abs_url": true} }}, "author": {"selector": ".author", "type": "object", "fields": { "name": {"selector": ".name"}, "bio": {"selector": ".bio"} }} }} 字段类型:text(默认,节点归一化文本)/ html / attr(需配 attr)/ count(匹配节点数)/ list(配 fields 返回对象数组,否则按 list_key 取值)/ object(在第一个匹配节点内部继续按 fields 抽取)/ jsonld(不写 selector,用 path 从 JSON-LD 取值,如 {"type": "jsonld", "path": "author.name"})。 后处理:regex + group(正则提取,未命中回落 default)、abs_url(相对链接转绝对)、 strip(去首尾空白,默认 true)、convert(int / float / date,date 输出 ISO 8601)、 required(必填,缺失时整体 ok=false 并返回 missing_required)。
Args:
url: 目标网页完整 URL。
schema: 字段抽取规则字典,见上方示例;不传则套用该站 recipe 的 extract 规则。
headers: 自定义请求头;传入时不走共享缓存。
cookies: 自定义 cookie 字典;传入时不走共享缓存。
timeout: 单次请求超时秒数。
deadline_ms: 整次调用的总预算(毫秒),不传表示不限;降级规则同 web_fetch。
wait_for: 仅 L2 生效,等待该 CSS 选择器出现后再取内容;不传则套用站点 recipe。
scroll: 仅 L2 生效,滚动页面触发懒加载;不传则套用站点 recipe。
click: 仅 L2 生效,渲染后点击一次该 CSS 选择器;不传则套用站点 recipe。
bypass_cache: 跳过并绕过响应缓存,强制走网络。
debug: 返回 diagnostics(分层决策与 L2 交互命中情况),不含页面内容。
session: 登录态会话名(默认 default);需与 login 时使用的会话名一致。
proxy: 本次请求使用的代理(如 http://127.0.0.1:7890);不传则按代理池分配,
未配池时沿用全局配置。显式传入代理的请求不读也不写共享缓存。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| click | No | ||
| debug | No | ||
| proxy | No | ||
| schema | No | ||
| scroll | No | ||
| cookies | No | ||
| headers | No | ||
| session | No | default | |
| timeout | No | ||
| wait_for | No | ||
| deadline_ms | No | ||
| bypass_cache | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |