> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/cn/web-api/scrape.md).

# /scrape

了解如何使用 Oxylabs Web API /scrape 端点，以所需格式获取和解析任意网页。

该 `/v1/scrape` 该端点通过 URL 抓取网页，自动处理无头浏览器渲染、代理轮换、访问挑战和本地化。它以 Markdown、HTML、JSON 或 PNG 截图形式返回结构化页面数据。

## 请求示例

该端点接受一个 JSON 载荷，用于定义目标 URL、请求的输出格式、渲染选项和地理位置上下文。

```bash
curl https://webapi.oxylabs.io/v1/scrape \
  -H "Authorization: Bearer $OXYLABS_WEB_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
      "url": "https://artificialintelligenceact.eu/implementation-timeline/",
      "output": ["markdown"]
  }'
```

### 请求参数

<table><thead><tr><th width="98">参数</th><th width="566">说明</th><th width="93">类型</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><code>url</code></mark></td><td>绝对 <code>http</code> / <code>https</code> 目标 URL。</td><td>字符串</td></tr><tr><td><code>output</code></td><td>响应格式： <code>markdown</code>, <code>html</code>, <code>json</code>, <code>screenshot</code>。支持多个值。默认： <code>html</code></td><td>字符串数组</td></tr><tr><td><code>json</code></td><td>当 <code>output: ["json"]</code>时，可通过 <code>prompt</code> 或 <code>schema</code>。请参阅 <a href="https://developers.oxylabs.io/products/cn/web-api/scrape/ai-jie-xi.md">AI 解析</a>.</td><td>对象</td></tr><tr><td><code>location</code></td><td>两位字母的 ISO 3166-1 alpha-2 国家代码（例如， <code>"US"</code>, <code>"DE"</code>, <code>"JP"</code>).</td><td>字符串</td></tr><tr><td><code>device</code></td><td>User-Agent 和视口模拟： <code>"desktop"</code> （默认）或 <code>"mobile"</code>. </td><td>字符串</td></tr><tr><td><code>run_js</code></td><td>设置为时启用 JavaScript 渲染 <code>true</code>。默认： <code>false</code>.</td><td>布尔值</td></tr></tbody></table>

&#x20;    – 必填参数。

<details>

<summary><strong><code>output</code></strong></summary>

该 `output` 数组允许在一次请求执行中获取多种输出格式。以下是组合输出请求示例：

```json
{
  "url": "https://example.com/product",
  "output": ["markdown", "json"],
  "json": {
    "prompt": "提取产品名称、库存状态和价格，并以数字形式返回。"
  }
}
```

<table data-header-hidden><thead><tr><th width="119"></th><th></th></tr></thead><tbody><tr><td><code>markdown</code></td><td>将 DOM 树转换为干净、结构化的 Markdown，去除导航脚本和样式格式。针对摄取到 LLM 上下文窗口进行了优化，以尽量减少 token 使用量。</td></tr><tr><td><code>html</code></td><td>原始页面标记。需要标记本身（属性、嵌入的 JSON-LD、内联数据）时使用。不建议用于采集页面内容。</td></tr><tr><td><code>screenshot</code></td><td>完全渲染页面的 Base64 编码 PNG 图片。 <strong><code>run_js: true</code> 是必需的</strong>，否则请求将被拒绝。</td></tr><tr><td><code>json</code></td><td>在与抓取相同的请求中进行结构化提取（无需编写或维护选择器）。使用专用解析器（适用于受支持的目标）或 <a href="https://developers.oxylabs.io/products/cn/web-api/scrape/ai-jie-xi.md">AI 解析</a> 由你通过描述字段来定义一个 <code>prompt</code>，或者通过一个精确固定其形状的 <code>schema</code>.</td></tr></tbody></table>

{% hint style="info" %}
**例外：** `video` 输出格式仅适用于 `/scrape/media` [专用抓取器](https://developers.oxylabs.io/products/cn/web-api/scrape/zhuan-yong-zhua-qu-qi.md).
{% endhint %}

</details>

<details>

<summary><strong><code>run_js</code></strong></summary>

在捕获内容之前执行页面自身的 JavaScript。

省略 `run_js` 会默认采用适用于给定源路径的最佳执行路径。显式设置 `"run_js": true` 会使用无头浏览器实例执行客户端脚本、动态 XHR 请求以及单页应用（SPA）渲染。

```json
{
  "url": "https://example.com/spa-dashboard",
  "output": ["markdown"],
  "run_js": true
}
```

* **延迟影响：** 无头浏览器渲染会显著增加请求时长。请将客户端 HTTP 超时时间设置为至少 `150` 秒。当需要高吞吐量时， [异步交付](https://developers.oxylabs.io/products/cn/web-api/scrape/jiao-fu-mo-shi.md) 建议使用。
* **资源优化：** 务必先尝试在不使用它的情况下抓取内容。对于静态页面或 RSS/Atom 源，请传入 `"run_js": false` 以最大化请求吞吐量并最小化延迟。仅在必要时选择渲染。

</details>

<details>

<summary><strong><code>location</code></strong></summary>

地理定向会通过本地化代理出口节点路由请求。这可确保本地化定价、语言变体和区域专属内容正确返回。

```json
{
  "url": "https://example.com/pricing",
  "output": ["html"],
  "location": "DE",
  "check_empty_geo": true
}
```

{% hint style="info" %}
当使用 [专用抓取器](https://developers.oxylabs.io/products/cn/web-api/scrape/zhuan-yong-zhua-qu-qi.md)时，某些本地化参数的名称可能不同。
{% endhint %}

</details>

## 输出示例

成功的请求会返回 HTTP `200 OK` 状态码，并带有标准信封结构。内部字段 `results[]` 中未请求的输出格式返回 `null`.

```json
{
  "status": 200,
  "results": [
    {
      "html": null,
      "markdown": "# Implementation Timeline\n\nProviders need to be compliant...",
      "screenshot": null,
      "json": null,
      "metadata": {
        "page": 1,
        "run_js": false,
        "url": "https://artificialintelligenceact.eu/implementation-timeline/"
      }
    }
  ],
  "params": {
    "url": "https://artificialintelligenceact.eu/implementation-timeline/",
    "output": ["markdown"],
    "json": { "schema": null, "prompt": null },
    "location": null,
    "device": "desktop",
    "run_js": null
  },
  "metadata": {
    "timestamp": 1787431568,
    "request_id": "7503078851572948993"
  }
}
```

{% hint style="info" %}
**`results[]` 字段中未请求的输出格式返回 `null`.** \
例如，请求 `["markdown"]` 会填充 `markdown` 并将 `html`, `screenshot` 和 `json` 留为 null。任何 [专用抓取器](https://developers.oxylabs.io/products/cn/web-api/scrape/zhuan-yong-zhua-qu-qi.md) 会将其结构化字段放在 `json`.
{% endhint %}

### 输出字典

<table><thead><tr><th width="208">字段</th><th>说明</th><th width="92">类型</th></tr></thead><tbody><tr><td><code>status</code></td><td>HTTP 状态码， <code>200</code> 在成功时。参见 <a href="https://developers.oxylabs.io/products/cn/web-api/gu-zhang-pai-cha.md">错误代码</a>.</td><td>整数</td></tr><tr><td><code>结果</code></td><td>所请求 URL 对应一条条目。</td><td>数组</td></tr><tr><td><code>results[].markdown</code></td><td>如果请求了，则返回页面的 Markdown。 <code>null</code> 否则。</td><td>字符串</td></tr><tr><td><code>results[].html</code></td><td>如果请求了，则返回原始结果标记。 <code>null</code> 否则。</td><td>字符串</td></tr><tr><td><code>results[].json</code></td><td>来自 <a href="https://developers.oxylabs.io/products/cn/web-api/scrape/zhuan-yong-zhua-qu-qi.md">专用抓取器</a> 或 <a href="https://developers.oxylabs.io/products/cn/web-api/scrape/ai-jie-xi.md">AI 解析器</a>的解析字段，如果请求了 <code>null</code> 否则。</td><td>对象</td></tr><tr><td><code>results[].screenshot</code></td><td>如果请求了，则返回 Base64 编码的图像字符串。 <code>null</code> 否则。</td><td>字符串</td></tr><tr><td><code>results[].metadata.url</code></td><td>重定向后用于抓取的已获取 URL。</td><td>字符串</td></tr><tr><td><code>params</code></td><td>所有参数均使用已应用默认值的请求。</td><td>对象</td></tr><tr><td><code>metadata.timestamp</code></td><td>以秒为单位的 Unix 时间戳。</td><td>整数</td></tr><tr><td><code>metadata.request_id</code></td><td>此请求的标识符。 <strong>在支持工单中包含它。</strong></td><td>字符串</td></tr></tbody></table>

## 延迟与并发

一次抓取会使用预算渲染真实页面，耗时为 **秒，而不是毫秒**。我们建议围绕这一点采用几项安全实践：

<table data-header-hidden><thead><tr><th width="123"></th><th></th></tr></thead><tbody><tr><td><strong>客户端超时</strong></td><td>150 秒是一个安全的默认值，而 10 秒超时可能会在本可成功的页面上失败。对于更高吞吐量（例如媒体、大规模 SERP 运行等）且存在客户端超时风险的情况，请使用异步交付而不是阻塞请求来运行相同的抓取器。参见 <a href="https://developers.oxylabs.io/products/cn/web-api/scrape/jiao-fu-mo-shi.md">交付模式</a>.</td></tr><tr><td><strong>并发限制</strong></td><td>并行抓取十个搜索结果会为你不会阅读的页面成倍增加成本和延迟。只抓取两个或三个最可能回答问题的结果，并仅逐步提高并发，直到 <code>429</code> 达到错误为止。</td></tr></tbody></table>

## 专用抓取器

除了通用 URL 抓取外，还可以将目标特定抓取器与 `POST /v1/scrape/{target}/{collection}`一起使用。它们接受目标特定参数（例如 ASIN、浏览节点、商店邮政编码），并将结构化字段返回到 `results[].json`:

```bash
curl https://webapi.oxylabs.io/v1/scrape/amazon/product \
  -H "Authorization: Bearer $OXYLABS_WEB_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "query": "B0935DN1BN",
    "output": ["json"],
    "location": "10115",
    "domain": "de",
    "currency": "EUR"
  }'
```

参见 [专用抓取器](https://developers.oxylabs.io/products/cn/web-api/scrape/zhuan-yong-zhua-qu-qi.md) 以查看目标概览（Google、Amazon、YouTube、Bing、AI 与 LLM、Commerce 等）。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.oxylabs.io/products/cn/web-api/scrape.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
