From f03c4e7410b8b095bdcb94f59283442a956630f0 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2026 07:04:17 +0000 Subject: [PATCH] feat: add /extract endpoint for one-shot structured page extraction Co-Authored-By: nathan schofi --- SKILL.md | 11 ++ references/cdp-api.md | 31 ++++++ scripts/cdp-proxy.mjs | 246 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+) diff --git a/SKILL.md b/SKILL.md index 7cfaaf6..4434167 100644 --- a/SKILL.md +++ b/SKILL.md @@ -120,6 +120,11 @@ curl -s -X POST "http://localhost:3456/clickAt?target=ID" -d 'button.upload' # 文件上传 — 直接设置 file input 的本地文件路径,绕过文件对话框 curl -s -X POST "http://localhost:3456/setFiles?target=ID" -d '{"selector":"input[type=file]","files":["/path/to/file.png"]}' +# 一次性提取页面结构化信息(链接/图片/视频/正文/时间等) +curl -s "http://localhost:3456/extract?target=ID" +# 或传 URL 一步到位(自动开 tab → 提取 → 关闭) +curl -s "http://localhost:3456/extract?url=https://example.com" + # 滚动(触发懒加载) curl -s "http://localhost:3456/scroll?target=ID&y=3000" curl -s "http://localhost:3456/scroll?target=ID&direction=bottom" @@ -137,6 +142,12 @@ curl -s "http://localhost:3456/close?target=ID" 很多网站的链接包含会话相关的参数(如 token),这些参数是正常访问所必需的。提取 URL 时应保留完整地址,不要裁剪或省略参数。 +### 页面信息提取 + +`/extract` 端点可一次性提取页面的完整结构化信息(标题、正文、链接、图片、视频、音频、时间、meta、JSON-LD),适合爬取场景。支持传 `target`(已打开的 tab)或 `url`(自动开 tab → 提取 → 关闭),自动滚动触发懒加载。详见 `references/cdp-api.md`。 + +需要更精细控制时,仍可用 `/eval` 手写 JS 定向提取。 + ### 媒体资源提取 判断内容在图片里时,用 `/eval` 从 DOM 直接拿图片 URL,再定向读取——比全页截图精准得多。 diff --git a/references/cdp-api.md b/references/cdp-api.md index 71feba8..ec3113d 100644 --- a/references/cdp-api.md +++ b/references/cdp-api.md @@ -88,6 +88,37 @@ curl -s "http://localhost:3456/scroll?target=ID&direction=bottom" curl -s "http://localhost:3456/screenshot?target=ID&file=/tmp/shot.png" ``` +### GET /extract?target=ID 或 /extract?url=URL +一次性提取页面结构化信息。两种用法: +- 传 `target`:对已打开的 tab 提取 +- 传 `url`:自动创建后台 tab → 提取 → 关闭 tab(一步到位) + +自动滚动到底部触发懒加载后再提取,确保动态内容已加载。 + +```bash +# 对已有 tab 提取 +curl -s "http://localhost:3456/extract?target=TARGET_ID" + +# 传 URL 一步到位(自动开 tab → 提取 → 关闭) +curl -s "http://localhost:3456/extract?url=https://example.com" +``` + +返回 JSON 包含以下字段: + +| 字段 | 说明 | +|------|------| +| `title` | 页面标题 | +| `url` | 当前 URL | +| `meta` | description、keywords、author、og 标签、canonical 等 meta 信息 | +| `times` | 时间信息(`