使用场景

用 API 从任意网站提取结构化数据

把网页变成 JSON:把页面读取为 Markdown、爬取整个网站、截取网页截图,或让浏览器智能体逐步点击操作,按你的结构填好数据。

预付费,无订阅REST 或 MCP一个密钥搞定模型、数据和智能体
shop.example.com/search?q=deskdataname: "Oak desk"price: 249.00rating: 4.7name: "Standing desk"price: 389.00rating: 4.5

你想把网页转 JSON,让网站上的数据变成代码能直接使用的格式:一张价格表、产品规格、一份名录、一组在招职位。选择能完成任务的最轻量的工具。平台已有对应的目录工具时就用它;数据就在公开页面上时,读取页面或爬取网站即可;必须先搜索、筛选、点击或登录才能看到数据时,再使用带 output_schema 的浏览器智能体。

交给你的 AI 智能体

把这段提示词复制到 Claude Code、Cursor、Codex 或任何编程智能体中。它会告诉智能体文档在哪里,以及如何使用你的 API 密钥。

Extract structured data from websites for me with Lovely Router: read pages as Markdown, crawl whole sites, take screenshots, or let the browser agent click through pages and fill a JSON schema.

- Docs (read first): https://lovelyrouter.com/docs/tools/run.md and https://lovelyrouter.com/docs/browser-agent/structured-output.md
- Simple pages (read a page as Markdown, crawl a site, screenshots, contact details): data tools. Plan with POST https://lovelyrouter.com/v1/tools/suggest and `{"task": "..."}` (free): it returns the tools to run, example inputs, estimated costs and ready-made run requests. Run with POST https://lovelyrouter.com/v1/tools/<id>/run; a 202 means poll the `poll` path.
- Pages that need clicks, logins or forms: POST https://lovelyrouter.com/v1/browser/runs with `{"goal": "...", "start_url": "...", "output_schema": {...}}` and read `data` when the run ends (docs: https://lovelyrouter.com/docs/api/browser.md).
- Prefer the cheapest tool that works: page reading and crawls cost less than browser steps.
- If you support MCP, you can instead connect the server https://lovelyrouter.com/mcp (Streamable HTTP, same key; https://lovelyrouter.com/docs/tools/mcp.md) and use suggest_tools, get_tool and run_tool.
- Auth: read my API key from the LOVELY_API_KEY environment variable and send it as `Authorization: Bearer $LOVELY_API_KEY`. Never print or commit the key. If it is not set, ask me to create one at https://lovelyrouter.com/app/keys.
- Billing is prepaid: every call is charged to my balance, so test with a small request before running anything large.
- Every docs page is plain Markdown; the full index is https://lovelyrouter.com/llms.txt.

My task: <the site or URLs and the fields you need, as a JSON schema if you have one>
01

选择合适的工具

你的情况使用你得到的结果
目录已覆盖的平台,例如 Google Maps、Amazon 或 LinkedIn该平台的工具,例如 Google Maps 地点平台自身的字段,按结果计价
你已知 URL 的单个页面读取网页页面标题和正文,转成干净的 Markdown
同一网站的大量页面爬取网站每个页面都是可直接交给 LLM 的 Markdown
邮箱、电话和社交媒体链接网站联系方式按网站合并的联系方式,最多爬取 5 个页面
页面的外观网页截图整页 PNG、JPEG、WebP 或 PDF 的链接
藏在搜索框、筛选条件、"加载更多"按钮或登录之后的数据带 output_schema 的浏览器智能体按你的结构校验过的 JSON

MCP 服务器也会给智能体同样的建议:用 web_search 和 web_fetch 查找信息和读取页面,把浏览器智能体留给需要交互的页面,以及没有工具覆盖的网站。

02

工作原理

010203
  1. 先查工具目录

    把任务描述发送到 POST /v1/tools/suggest,或用 POST /v1/tools/discover 搜索。两者都免费,并会返回工具、示例输入和费用。参阅找到合适的工具。

  2. 读取或爬取公开页面

    对单个 URL 运行 web-fetch,或对某个栏目运行 website-crawl,再用你自己的解析器或同一密钥下的模型把 Markdown 转成 JSON。

  3. 必须交互时,按结构提取

    用一个目标、一个起始 URL 和一个 output_schema 启动浏览器智能体运行。智能体会逐步点击操作,并在 data 中返回符合你结构的 JSON。

03

按你的结构获取 JSON

{}

下面这次运行会打开一家书店的 Travel 分类,并把页面上的每本书以 JSON 返回:

cURL
curl https://lovelyrouter.com/v1/browser/runs \
  -H "Authorization: Bearer $LOVELY_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "goal": "Open the Travel category and list every book on the first page with its title, price, star rating, stock status and link.",
    "start_url": "https://books.toscrape.com/",
    "output_schema": {
      "books": [{"title": "string", "price": "price as shown, with currency", "rating": "star rating as shown", "in_stock": "boolean", "url": "string"}]
    }
  }'

响应为 202,并带有运行的 id。反复请求 GET /v1/browser/runs/{id}?wait=30 直到运行结束,然后读取 data。简写形式把每个字段映射到一个类型;像 "price as shown, with currency" 这样的描述会让该字段成为一个字符串,由智能体按你的描述填写。如果需要枚举、格式和必填字段,请改为发送完整的 JSON Schema(draft 2020-12),最大 20 KB。

让输出可以放心使用的原因:

经过校验。

JSON 会按你的结构进行校验。如果第一次尝试未通过,智能体会拿到错误信息并修正一次;如果仍然失败,data_error 会说明原因。

取自页面。

data 根据智能体访问过的页面的文本和链接生成,因此链接 URL 都是真实的。页面上没有的值会返回 null,没有内容的列表会返回空列表。

不额外收费。

结构化输出已包含在每步价格中。

04

无需浏览器即可读取和爬取

对于公开页面,用浏览器有些大材小用。下面这次爬取会读取招聘栏目,最多 50 个页面:

cURL
curl https://lovelyrouter.com/v1/tools/website-crawl/run \
  -H "Authorization: Bearer $LOVELY_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "input": {
      "startUrls": [{"url": "https://www.example.com/careers/"}],
      "maxCrawlDepth": 2,
      "excludeUrlGlobs": ["https://www.example.com/careers/archive/**"]
    },
    "max_results": 50
  }'

每一条结果都是一个 Markdown 格式的页面。把这些页面连同你需要的字段一起交给模型,就能得到 JSON 格式的在招职位。includeUrlGlobs 可以把爬取范围扩展到起始 URL 的子页面之外,useSitemaps 会加入网站 sitemap 中的 URL。

06

实用配方

把定价页整理成对比表。

用 {"plans": [{"name": "string", "price_per_month": "number", "includes_sso": "boolean"}]} 对每个竞品的定价页运行浏览器智能体。长表格请使用 "mode": "accurate":它不仅能读取可见文本,还能用只读的页面代码读取表格。

搜索表单背后的结果。

把搜索词写进目标("搜索降噪耳机,获取前 5 条结果"),并在结构中描述各个字段。数据来自智能体最后访问的六个页面,因此很长的分页列表请拆成多次运行,每次处理一页或一组页面。

需要登录的数据源。

在提取运行中传入保险库 secrets 或已保存的 profile。密钥值永远不会出现在 data 中。

存档快照。

用 "format": "pdf" 运行 website-screenshot,整页留存某个页面在某一天的内容;内容加载较慢时,设置 delayMs。

从一批网站获取联系方式。

把这些网站作为 startUrls 发给 website-contacts,按网站获取邮箱、电话和社交媒体链接。

07

费用说明

读取一个页面的费用为 $0.0009,无法读取的页面不收费。爬取、截图和联系方式工具按页面、截图或网站计费,爬取工具另收每次调用费;上方卡片显示的是当前价格。浏览器智能体按步骤计费,快速模式每步 $0.006,精准模式每步 $0.012,已包含模型和结构化输出,没有单次运行费。每次运行都会先预留最高费用,结束后按实际用量结算。无需订阅。参阅价格。

08

常见问题

?
什么时候应该用浏览器智能体,而不是采集工具?+

平台已有对应的目录工具时就用它,公开页面用 web-fetch 或 website-crawl。只有当数据必须在搜索、筛选、点击或登录之后才会出现时,才使用浏览器智能体来做 AI 网页抓取。

提取出的 JSON 会按我的结构校验吗?+

会。结果会经过校验,如果第一次尝试不符合结构,智能体会修正一次。如果提取仍然失败,data 为 null,data_error 会给出原因。

页面上没有某个字段时会怎样?+

该字段会返回 null,列表会返回空列表。智能体只根据它访问过的页面生成数据,从不靠猜测填写值。

能把整个网站转成 Markdown 吗?+

可以。website-crawl 工具会把一个网站或栏目的每个页面以干净的 Markdown 返回,并支持限制页数和深度,以及用 URL 规则包含或排除页面。

结构化输出要额外收费吗?+

不需要。结构化输出已包含在浏览器智能体的每步价格中。

相关内容:提交表单请看网页自动化,搜索和 RAG 请看研究智能体,另见结构化输出指南。

一个预付费密钥,搞定模型、数据和智能体

无需订阅。充值后按需使用,每笔费用都能在日志中查看。