用途:chrome-agent extract 用于从网页中提取重复出现的结构化记录,例如商品网格、搜索结果、职位列表、新闻流和表格,并以 JSON 返回,无需手写 CSS 选择器。
主要能力:自动识别页面上得分最高的重复记录模式;支持 --selector 限定容器、--limit 控制条数(默认 10)、--scroll 处理懒加载与无限滚动、--a11y 在 React/SPA 页面改用无障碍树。--json 输出 {"ok":true,"count":N,"pattern":"...","items":[...]},每项含 title、url(如有)及 fields 文本。
用法示例: which chrome-agent || npm install -g chrome-agent chrome-agent goto https://news.ycombinator.com chrome-agent --json extract --limit 50 chrome-agent extract --selector ".product-grid" chrome-agent extract --a11y --scroll --limit 50
无结果时的回退顺序:chrome-agent network --filter "api"、chrome-agent read、chrome-agent text --selector "main"、chrome-agent eval。登录与反爬可用 --copy-cookies、--stealth、--connect http://127.0.0.1:9222。
限制:只识别一个模式,多个等强列表需用 --selector;只读取已渲染内容,悬停或点击后才出现的内容不包含;字段为位置性文本而非类型化 schema;下载链接需先用 inspect --urls 取 href 再交给 chrome-agent download。错误时退出码为 1,仍会在 stdout 输出 JSON 及提示。