第9章 网页抓取 API
获取页面数据 调用 /scrape 接口,传入一个或多个 URL,系统将返回可见文本、页面结构及链接记录。后续的数据处理环节,你可以接入自有的模型或工作流。
01 文本与结构 返回清洗后的页面文本、无障碍树(accessibility tree)以及元素链接。 02 无规划器(Planner) 直接利用浏览器和代理层处理请求,无需由 Agent 决策路由。 03 易于组合 可将响应结果直接接入自有的搜索、RAG 或数据增强系统中。
命令行(CLI) 通过 rtrvr CLI 在终端中获取相同的页面数据: `rtrvr scrape --url https://example.com`
实操演示 描述数据,获取整洁的页面输出 Scrape API 演示视频
POST /scrape 端点 添加 URL,获取可读文本、页面结构和链接。[试一试] [获取 API 密钥]
创建 API 密钥 输入页面 URL `https://news.ycombinator.com/` 每行添加一个完整的 URL。
```bash curl -X POST https://api.rtrvr.ai/scrape \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "urls": [ "https://news.ycombinator.com/" ], "response": { "inlineOutputMaxBytes": 1048576 } }' ``` 添加你的 API 密钥即可运行此请求。
基础 URL (Base URL) `https://api.rtrvr.ai` 处理原始页面数据使用 /scrape,执行完整 Agent 运行使用 /agent。
在 Authorization 头部中使用你的 API 密钥: `Authorization: Bearer rtrvr_your_api_key` Bearer 前缀可选(即 `Authorization: rtrvr_your_api_key` 也有效),`x-api-key: rtrvr_your_api_key` 同样被接受。在 n8n、Make 或 Zapier 的 Header Auth 设置中,将 Name 设为 Authorization 或 x-api-key,Value 设为你的密钥即可。 安全提示: 请确保密钥仅存储在服务端(后端或无服务器环境),切勿发送至浏览器端。
POST 端点 `https://api.rtrvr.ai/scrape`
Agent vs Scrape 若需要完整的规划器 + 工具引擎,请使用 /agent;若仅需获取原始页面文本和结构以便自有模型处理,请使用 /scrape。[查看对比]
核心机制 在集群浏览器中打开一个或多个 URL,返回每个页面的无障碍树(含链接)或纯文本。该端点的设计目标为: - 低成本 – 仅消耗基础设施额度(浏览器 + 代理),不涉及模型调用费用。 - 可预测 – 标签页内容与使用指标的结构化 Schema 保持稳定。 - 可组合 – 结果可直接插入自有的 LLM 或 RAG 管道。
最小化 Scrape 示例(单 URL) ```bash curl -X POST https://api.rtrvr.ai/scrape \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "urls": ["https://example.com/blog/ai-trends-2025"] }' ``` 提取偏好设置取自云端存储的 UserSettings 配置。
UserSettings 相关字段(概念示意) ```typescript interface UserSettings { extractionConfig: { maxParallelTabs?: number; / Minimum wait inside totalBudgetMs; default 0. */ pageLoadDelay?: number; / Initial read deadline: default 15000, bounded to 1500–30000 ms. */ totalBudgetMs?: number; makeNewTabsActive?: boolean; writeRowProcessingTime?: boolean; disableAutoScroll?: boolean; / * When true, only text content is returned from scrapes. * The accessibility tree + elementLinkRecord are omitted. * When false (the default), HTML pages return tree + elementLinkRecord * and no content. */ onlyTextContent?: boolean; };
// Proxy Configuration proxyConfig: { mode: 'none' | 'custom' | 'default' | 'device'; customProxies?: ProxySettings[]; selectedProxyId?: string; selectedProxyName?: string; selectedDeviceId?: string; // Managed proxy exit (mode 'default'): ISO country, optional ISO 3166-2 // region part ("NY", "25") and English city name. location?: { country: string; region?: string; city?: string }; }; } ```
两种行为控制方式: 1. 云端配置(Cloud profile): 在 Cloud → Settings 中配置默认值。 2. 单请求覆盖(Per-request overrides): 在请求体中传入设置。
使用 MCP 或 API 中保存的代理 在 Cloud Settings → Proxy Config 中保存代理。将其设为默认并保存配置,即可在 Cloud、API 和 MCP 中通用。若仅需单次调用覆盖,传入其精确名称或 ID 即可。凭证保留在你的账户中。 ```json { "settings": { "proxyConfig": { "mode": "custom", "selectedProxyName": "My Taiwan proxy" } } } ``` 对于 cloud_agent 和 cloud_scrape,将 settings 放入 MCP 工具的 arguments 或工具 API 的 params 中。对于 POST /agent 和 POST /scrape,将其放入请求体。已保存的 selectedProxyId 可替代 selectedProxyName。
省略 proxyConfig 将使用配置文件的默认值;若未设置,则回退至 Retriever 托管代理。使用 `{"mode":"default"}` 可显式选择托管代理。
Cloud 聊天栏中的选择仅覆盖该会话的路由,不改变配置文件默认值。选择“Use my default route”可重置此设置。MCP 列表(kind: "proxies")显示已保存的代理并标记默认项;托管代理的连接细节保持私密。 使用 `{"mode":"none"}` 进行直接云端连接。
已保存的名称区分大小写。未知名称或 ID 会导致失败;名称重复时需指定 ID。若同时提供两个选择器,它们必须指向同一个代理。
由运行创建的调度任务(Schedules)会保留其路由选择。使用其他路由的权限属于调度任务,因此单次运行的回退不会自动启用新路由。
单次请求自定义代理 可以为单次请求提供代理。需使用支持 CONNECT 的 HTTP 或 HTTPS 代理,并确保凭据不出现在共享代码片段或客户端代码中。 ```json { "settings": { "proxyConfig": { "mode": "custom", "selectedProxyId": "request-proxy", "customProxies": [ { "id": "request-proxy", "host": "proxy.example.net", "port": 8080, "scheme": "http", "username": "YOUR_USERNAME", "password": "YOUR_PASSWORD" } ] } } } ```
通过 Tailscale 从自有电脑出站 Tailscale 隧道使云端运行的流量通过你拥有的电脑出站,网站看到的就是你的家庭连接。此方式不消耗代理额度。保存后,可像使用普通保存的代理一样选择它:设为默认、在聊天栏选择,或通过 `{"mode":"custom"}` 指定其精确名称或 ID。
Tailscale 连接失败重试一次后即停止,任务启动前终止。若允许 API 请求在 Tailscale 失败时回退至托管代理,发送 `settings.proxyConfig.tailscaleFallback: "managed"`。省略该字段或使用 "stop" 则保持使用 Tailscale。回退将使用不同的 IP,并适用正常的代理计费。 [设置 Tailscale 隧道:步骤、限制及并行运行说明]
选择托管代理出口位置 在 Retriever 托管代理中添加 location,可指定国家,并可选地区或城市。云浏览器的时区和语言将跟随出口位置,网站将按当地访客视角展示日期、价格和页面。 ```json { "settings": { "proxyConfig": { "mode": "default", "location": { "country": "IT", "city": "Milan" } } } } ``` 单字段最多可列出 5 个位置以供出口选择:国家(`{"country": ["IT", "FR", "DE"]}`,不含地区或城市)、单一国家的地区(`{"country": "US", "region": ["CA", "WA"]}`,不含城市)或单一国家的城市(`{"country": "IT", "city": ["Milan", "Rome"]}`)。逗号分隔的字符串如 "IT,FR,DE" 也有效。egress 字段指明运行实际使用的国家。
结果的 egress 说明运行出口位置,例如 `{"country":"IT","city":"Milan","timezone":"Europe/Rome"}`。`relaxed: true` 表示指定城市或地区无出口,运行使用了该国范围内的其他位置。
Location 仅适用于托管代理(`mode: "default"`,省略 mode 时隐含此项)。若旁边指定了保存的代理或 "none",该调用将被拒绝。
字段通用性: POST /agent 和 POST /scrape 中均使用 `settings.proxyConfig.location`,MCP 工具 cloud_agent 和 cloud_scrape 同理。MCP 和工具 API 也接受简写 `proxy_location`,例如 `"proxy_location": "IT"`、`"proxy_location": "IT,FR,DE"` 或 `"proxy_location": {"country": "US", "region": "NY"}`;若使用 agent 或 scrape,任务将在云浏览器中运行。
在 Cloud Settings → Proxy Config 中保存位置(靠近托管默认项),可用于所有未指定路由的运行(含调度任务)。在 Cloud 聊天栏中,选择 Retriever managed proxy 并仅为该会话设置 Location。
少数始终直接从云端连接的主机(如某些政府网站和文件存储)不使用 Location 设置。
支持的位置 Location 指定国家,可选地区或城市。每个字段可填单一值,或最多 5 个值的列表(出口为其中之一即可)。
| 字段 | 格式 | 示例 | | :--- | :--- | :--- | | country | 两字母 ISO 3166-1 代码(UK 读作 GB)。国家列表不带 region 或 city。 | IT, US, ["IT", "FR", "DE"] | | region | 可选。ISO 3166-2 代码中该国部分(短横线后)。地区列表不带 city。 | US-NY 的 NY, IT-25 的 25 (Lombardy) | | city | 可选。该国城市的英文名称。 | Milan, New York, ["Milan", "Rome"] |
若城市无出口,运行将尝试其地区,再尝试全国。绝不会切换至其他国家。若指定国家均无出口,运行不会启动,调用返回 503 PROXY_LOCATION_UNAVAILABLE 并附带相应说明。
可用性是实时的: 出口随住宅代理池动态变化,每次运行启动前都会检查其位置。 使用 API 密钥调用 `GET https://api.rtrvr.ai/proxy-locations` 可获取上述国家列表、每个国家的检查日期、格式及回退规则。 若要即时检查地区、城市或列表,发送 `POST https://api.rtrvr.ai/proxy-location/check`,body 为 `{"location": {"country": "IT", "city": "Milan"}}`。 响应为 `{"available": true, "egress": {...}}` 指出运行出口位置,或 `{"available": false, "message": "..."}`。 Cloud Settings 和聊天栏执行相同检查,仅接受有出口的位置。
120 个国家在 2026 年 11 月 11 日检查时有出口: Åland Islands AX, Albania AL, American Samoa AS, Andorra AD, Anguilla AI, Antigua & Barbuda AG, Argentina AR, Armenia AM, Aruba AW, Australia AU, Austria AT, Azerbaijan AZ, Bahamas BS, Bahrain BH, Barbados BB, Belarus BY, Belgium BE, Belize BZ, Bermuda BM, Bosnia & Herzegovina BA, Brazil BR, British Virgin Islands VG, Bulgaria BG, Canada CA, Caribbean Netherlands BQ, Cayman Islands KY, Chile CL, China CN, Colombia CO, Costa Rica CR, Côte d’Ivoire CI, Croatia HR, Curaçao CW, Cyprus CY, Czechia CZ, Denmark DK, Dominica DM, Dominican Republic DO, Egypt EG, Equatorial Guinea GQ, Estonia EE, Falkland Islands FK, Faroe Islands FO, Finland FI, France FR, French Guiana GF, French Polynesia PF, Gabon GA, Georgia GE, Germany DE, Gibraltar GI, Greece GR, Greenland GL, Grenada GD, Guadeloupe GP, Guam GU, Guernsey GG, Hungary HU, Iceland IS, India IN, Iran IR, Ireland IE, Isle of Man IM, Israel IL, Italy IT, Jamaica JM, Japan JP, Jersey JE, Kazakhstan KZ, Kuwait KW, Latvia LV, Lithuania LT, Luxembourg LU, Malta MT, Martinique MQ, Mexico MX, Moldova MD, Monaco MC, Montenegro ME, Montserrat MS, Namibia NA, Netherlands NL, New Zealand NZ, North Macedonia MK, Norway NO, Oman OM, Palestinian Territories PS, Panama PA, Peru PE, Philippines PH, Poland PL, Portugal PT, Puerto Rico PR, Qatar QA, Romania RO, San Marino SM, Saudi Arabia SA, Serbia RS, Seychelles SC, Sint Maarten SX, Slovakia SK, Slovenia SI, South Korea KR, Spain ES, St. Kitts & Nevis KN, St. Lucia LC, St. Martin MF, St. Vincent & Grenadines VC, Sweden SE, Switzerland CH, Taiwan TW, Trinidad & Tobago TT, Türkiye TR, Turks & Caicos Islands TC, U.S. Virgin Islands VI, Ukraine UA, United Arab Emirates AE, United Kingdom GB, United States US, Uruguay UY
129 个国家在 2026 年 11 月 11 日检查时无出口: 这些代码可被接受,但仅要求这些国家的运行将被拒绝,直到出现出口。依赖前请先检查,或与有出口的国家并列。 Afghanistan AF, Algeria DZ, Angola AO, Antarctica AQ, Bangladesh BD, Benin BJ, Bhutan BT, Bolivia BO, Botswana BW, Bouvet Island BV, British Indian Ocean Territory IO, Brunei BN, Burkina Faso BF, Burundi BI, Cambodia KH, Cameroon CM, Cape Verde CV, Central African Republic CF, Chad TD, Christmas Island CX, Cocos (Keeling) Islands CC, Comoros KM, Congo - Brazzaville CG, Congo - Kinshasa CD, Cook Islands CK, Cuba CU, Djibouti DJ, Ecuador EC, El Salvador SV, Eritrea ER, Eswatini SZ, Ethiopia ET, Fiji FJ, French Southern Territories TF, Gambia GM, Ghana GH, Guatemala GT, Guinea GN, Guinea-Bissau GW, Guyana GY, Haiti HT, Heard & McDonald Islands HM, Honduras HN, Hong Kong SAR China HK, Indonesia ID, Iraq IQ, Jordan JO, Kenya KE, Kiribati KI, Kyrgyzstan KG, Laos LA, Lebanon LB, Lesotho LS, Liberia LR, Libya LY, Liechtenstein LI, Macao SAR China MO, Madagascar MG, Malawi MW, Malaysia MY, Maldives MV, Mali ML, Marshall Islands MH, Mauritania MR, Mauritius MU, Mayotte YT, Micronesia FM, Mongolia MN, Morocco MA, Mozambique MZ, Myanmar (Burma) MM, Nauru NR, Nepal NP, New Caledonia NC, Nicaragua NI, Niger NE, Nigeria NG, Niue NU, Norfolk Island NF, North Korea KP, Northern Mariana Islands MP, Pakistan PK, Palau PW, Papua New Guinea PG, Paraguay PY, Pitcairn Islands PN, Réunion RE, Russia RU, Rwanda RW, Samoa WS, São Tomé & Príncipe ST, Senegal SN, Sierra Leone SL, Singapore SG, Solomon Islands SB, Somalia SO, South Africa ZA, South Georgia & South Sandwich Islands GS, South Sudan SS, Sri Lanka LK, St. Barthélemy BL, St. Helena SH, St. Pierre & Miquelon PM, Sudan SD, Suriname SR, Svalbard & Jan Mayen SJ, Syria SY, Tajikistan TJ, Tanzania TZ, Thailand TH, Timor-Leste TL, Togo TG, Tokelau TK, Tonga TO, Tunisia TN, Turkmenistan TM, Tuvalu TV, U.S. Outlying Islands UM, Uganda UG, Uzbekistan UZ, Vanuatu VU, Vatican City VA, Venezuela VE, Vietnam VN, Wallis & Futuna WF, Western Sahara EH, Yemen YE, Zambia ZM, Zimbabwe ZW
Location 不产生额外费用。 托管代理流量按 GB 计费,约 500 积分/GB(参考定价),无论是否使用 Location 费率相同。
页面读取时序 /agent 和 /scrape 会立即打开提供的 URL,并在数据就绪后尽快返回。在 settings.extractionConfig 下配置时序。请求值覆盖已保存的配置。若两者均未设置,则应用以下默认值。 totalBudgetMs:初始导航、就绪检查、提取及回退的统一截止时间。默认:15000。范围限制在 1500–30000 毫秒。这是最大值,非强制等待时长。 pageLoadDelay:可选的最小等待时间,针对内容渲染较慢的页面。默认:0。正值即使页面提前就绪也会刻意等待。这会消耗总预算,且必要时会被缩短以预留提取和回退时间。 maxParallelTabs:最多 8 个云标签页同时加载(默认及最大:8)。设低值可减少并发,设为 1 则顺序读取。每个活动批次获得新的页面读取预算,因此大批量 URL 耗时可能超过单个预算。
就绪即返回,初始读取上限 15 秒 ```json { "settings": { "extractionConfig": { "totalBudgetMs": 15000, "pageLoadDelay": 0 } } } ``` 若页面需已知 10 秒渲染等待,设置 `pageLoadDelay: 10000` 且 `totalBudgetMs: 20000`。这为剩余读取工作预留约 10 秒。延迟不会在截止时间之上累加。显式设置 `pageLoadDelay: 0` 以覆盖已保存配置中的延迟。
达到截止时间时,读取将返回可用的树或文本回退。若两者均不可读,将报告页面不可读,而非成功但空提取。纯文本 Scrape 返回无树的文本。无 URL 的 Agent 立即从空页面启动;/scrape 至少需要一个 URL。
此截止时间仅覆盖页面读取,不涉及浏览器配置、模型执行或整个 API 请求。后续 Agent 捕获保持默认 8 秒,除非你设置了预算。取消操作可中断运行中的任务。调用方超时时间应足够长以容纳所有批次和 Agent 工作;若响应丢失,先通过 trajectory ID 恢复再重试。
请求体为 ScrapeApiRequest: ```typescript / * Unique caller id for this scrape. Save it before dispatch to recover * results or cancel after a lost response. Reusing it returns HTTP 409. */ interface ScrapeApiRequest { trajectoryId?: string;
/ * One or more absolute URLs to load in the browser. * Must be a non-empty array of non-empty strings. */ urls: string[];
/
* Optional per-request settings override.
* Other settings merge with your profile; omitted proxyConfig uses the profile default, or the managed proxy if none is set.
*
* Use extraction-related settings if you only want text content and don't need
* the accessibility tree + elementLinkRecord.
*/
settings?: Partial
/ * Response size control for API callers. */ response?: { / * Max bytes allowed for the inline JSON response. * If the full response exceeds this, tabs remain inline as preview content, * and a StorageReference is returned under metadata.responseRef for full payload download. * Default: 1MB (1048576 bytes) */ inlineOutputMaxBytes?: number; };
/ * Optional execution options. * Set options.ui.emitEvents=true to write progress events for SSE/polling clients. * If omitted/false, no execution event stream is written. */ options?: { ui?: { emitEvents?: boolean; }; };
/ * Webhooks to call when the scrape completes, fails, or is cancelled. */ webhooks?: WebhookSubscription[]; }
interface WebhookSubscription {
/ The URL to POST to */
url: string;
/ Events to subscribe to. Defaults to all scrape events. */
events?: WebhookEvent[];
/ Optional custom headers */
headers?: Record
type WebhookEvent = | "rtrvr.scrape.succeeded" | "rtrvr.scrape.failed" | "rtrvr.scrape.cancelled"; ```
参数说明
01 urls (string[]) [必填] 一个或多个绝对 URL 用于抓取。必须是非空数组。
02 trajectoryId (string) [可选] 用于分组抓取(分析、可观测性)的稳定 ID。
03 settings (Partial
在抓取完成、失败或取消时接收 HTTP 回调。 Webhook 在抓取结束后异步投递。
Webhook 订阅
01 url (string) [必填] POST Webhook 负载的 HTTPS 端点。
02 events (WebhookEvent[]) 要订阅的事件。默认为所有抓取事件。
- rtrvr.scrape.succeeded
- rtrvr.scrape.failed
- rtrvr.scrape.cancelled
03 headers (Record
带 Webhook 的示例 带 Webhook 通知的抓取 ```bash curl -X POST https://api.rtrvr.ai/scrape \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "urls": ["https://example.com/page1", "https://example.com/page2"], "webhooks": [ { "url": "https://your-server.com/webhooks/scrape", "events": ["rtrvr.scrape.succeeded", "rtrvr.scrape.failed"], "secret": "whsec_your_signing_secret", "headers": { "X-Custom-Header": "my-value" } } ] }' ```
Webhook 负载 每次 Webhook 投递是一个带 JSON 封装的 POST 请求: ```json { "id": "whd_abc123...", // unique delivery id "event": "rtrvr.scrape.succeeded", "createdAt": "2025-01-15T10:30:00.000Z", "data": { "trajectoryId": "traj_xyz...", "success": true, "tabs": [...], "usageData": {...} } } ```
签名验证 提供 secret 时,每个请求包含 X-Rtrvr-Signature 头部: `text X-Rtrvr-Signature: t=1705312200,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd`
验证签名 (Node.js) ```javascript import crypto from 'crypto';
function verifyWebhookSignature(payload, signature, secret) { const [tPart, vPart] = signature.split(','); const timestamp = tPart.split('=')[1]; const receivedSig = vPart.split('=')[1];
// Recreate the signed payload const signedPayload = `${timestamp}.${JSON.stringify(payload)}`; const expectedSig = crypto .createHmac('sha256', secret) .update(signedPayload) .digest('hex');
// Timing-safe comparison return crypto.timingSafeEqual( Buffer.from(receivedSig), Buffer.from(expectedSig) ); } ```
存储并复用 Webhooks 在 Cloud → Webhooks 中保存你的 Webhook 端点,以便快速将其附加到任何执行中,无需每次重新输入 URL、密钥和事件。
API 响应为 ScrapeApiResponse: ```typescript interface ScrapedTab { tabId: number; url: string; title: string; contentType: string; status: "success" | "error"; error?: string;
/ * The page's visible text. HTML pages fill it when * extractionConfig.onlyTextContent is true, or with a text fallback when * the tree could not be read. PDFs and other documents return their text here. */ content?: string;
/ * The accessibility tree as a plain-text outline, not JSON. Do not JSON.parse it. * One element per line, indented by depth: "[role] text", then markers such * as [id=N]. Lines of plain page text start with "[]". Link lines carry their * URL inline: * [link] Learn more [id=8 href="https://iana.org/help/example-domains"] * Omitted when onlyTextContent is true. */ tree?: string;
/
* Element id -> href for the link elements in 'tree', e.g. { "8": "https://..." }.
* The same URLs already appear inline in 'tree'.
* Only present when 'tree' is present.
*/
elementLinkRecord?: Record
interface ScrapeUsageData { totalCredits: number; browserCredits: number; proxyCredits: number; totalUsd: number; requestDurationMs: number; proxyPageLoads: number; proxyTabsDataFetches: number; usingBillableProxy: boolean; }
interface ScrapeApiResponse { success: boolean; status: "success" | "error"; trajectoryId: string;
tabs?: ScrapedTab[]; usageData: ScrapeUsageData;
// Where the managed proxy exited, e.g. { country: "IT", city: "Milan", timezone: "Europe/Rome" } egress?: { country: string; countries?: string[]; region?: string; city?: string; timezone?: string; requested?: { country: string; region?: string; city?: string }; relaxed?: boolean };
metadata?: { taskRef?: string; inlineOutputMaxBytes: number; durationMs: number; outputTooLarge?: boolean; responseRef?: StorageReference; };
error?: string; } ```
标签页与内容
01 tabs (ScrapedTab[]) 每个 URL 对应一个标签页,顺序与输入 urls 相同。
02 tabs[].content (string) 可见页面文本。HTML 页面在 onlyTextContent=true 时返回,或作为树不可读时的回退。PDF 及其他文档在此返回文本。
03 tabs[].tree (string) 无障碍树,格式为缩进的纯文本大纲,非 JSON:每行一个元素,如 `[link] Learn more [id=8 href="https://…"]`。纯文本行以 `[]` 开头。onlyTextContent=true 时省略。
04 tabs[].elementLinkRecord (Record
默认设置下 https://example.com/ 的 tabs[0].tree: ``` [] This domain is for use in documentation examples without needing permission. ... [link] Learn more [id=8 href="https://iana.org/help/example-domains"] [title] Example Domain ``` 同一标签页返回 elementLinkRecord `{"8": "https://iana.org/help/example-domains"}`,无 content。若 `onlyTextContent: true`,则在 content 中返回页面文本,无 tree 或 elementLinkRecord。
基础设施用量 01 usageData.totalCredits (number) 此抓取消耗的总基础设施积分。 02 usageData.browserCredits (number) 浏览器使用归因的积分。 03 usageData.proxyCredits (number) 代理使用归因的积分。 04 usageData.requestDurationMs (number) 抓取请求的端到端延迟(毫秒)。
分发前保存唯一的 trajectoryId。 同一 ID 在 REST 和 MCP 中识别执行。若连接关闭或返回 HTTP 504,在发送新抓取前读取现有运行。
```http GET /executions?limit=50 GET /executions/YOUR_TRAJECTORY_ID POST /scrape/cancel Content-Type: application/json
{"trajectoryId":"YOUR_TRAJECTORY_ID"} ``` 每个请求使用你的 API 密钥。历史记录返回 nextCursor;作为下一页的 cursor 传入。运行查询返回其状态、使用的积分、保存的结果或下载引用。确认 completed 后再视用量为最终值。取消操作保留已产生的结果和费用。重用原始 Scrape ID 返回 HTTP 409,而非启动重复工作。
在 MCP 中,使用 `list_executions`(`{"source":"cloud","include_completed":true}`),然后使用 trajectoryId 调用 `check_results` 或 `cancel_execution`。云端运行和这些恢复工具不需要扩展设备。较旧的原始 Scrape 即使早于执行列表创建,也可通过 ID 读取。
服务会自动回收失败的浏览器。没有公开的浏览器重置操作。协调终端故障后,使用新 ID 进行刻意重试。若旧请求无 ID,向支持团队发送其 UTC 分发时间和 URL。
检查每个标签页的状态。 HTML 页面的树读取返回填充了内容的树且 content 为空;需要页面文本时使用 `extractionConfig.onlyTextContent=true`。部分捕获可能保留有用数据并附带观察警告。空启动页面不算成功的 HTTP 页面抓取。包含失败标签页的批次报告 success: false 并保留可读的兄弟标签页。
cURL 示例 ```bash # 使用配置文件默认值的基本抓取 curl -X POST https://api.rtrvr.ai/scrape \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "urls": ["https://example.com/blog/ai-trends-2025"], "response": { "inlineOutputMaxBytes": 1048576 } }'
# 带单次请求设置覆盖 curl -X POST https://api.rtrvr.ai/scrape \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "urls": [ "https://example.com/blog/ai-trends-2025", "https://example.com/pricing" ], "settings": { "extractionConfig": { "onlyTextContent": true }, "proxyConfig": { "mode": "default" } }, "response": { "inlineOutputMaxBytes": 1048576 } }' ```
下一步运行 在真实网站上运行示例。 使用 Chrome 处理当前页面。若运行需按计划继续或跨越多页,使用 Cloud。