> 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/jiao-fu-mo-shi.md).

# 交付模式

了解 Web API 如何交付结果：Realtime 响应、通过轮询或回调的异步任务、云存储交付及批量请求。

Web API 提供三种交付模式，以满足不同的工作负载需求和执行量。&#x20;

<table><thead><tr><th width="315">交付方式</th><th width="92">最大条目数</th><th width="143">目标</th><th width="215">适用于……</th></tr></thead><tbody><tr><td><a href="#realtime"><strong>Realtime</strong></a> （同步）<br><code>POST /v1/scrape/{source}</code></td><td>1</td><td>所有端点</td><td>低延迟请求、测试</td></tr><tr><td><a href="#single-job-delivery-async"><strong>异步单任务</strong></a> （轮询）<br><code>POST /v1/async/scrape/{source}</code></td><td>1</td><td>所有端点</td><td>高并发和大批量请求</td></tr><tr><td><a href="#batch-delivery-async"><strong>异步批量</strong></a> （批量队列）<br><code>POST /v1/async/scrape/batch/{source}</code></td><td>5,000</td><td>选择端点</td><td>批量采集</td></tr></tbody></table>

大多数 `/scrape` 端点均提供 **Realtime** 和 **异步** 结果交付选项，具体何时以及如何获取结果取决于请求路径。

```http
POST /v1/scrape/...          # realtime：结果作为响应返回
POST /v1/async/scrape/...    # async：创建任务并单独获取结果
```

## Realtime

```http
POST /v1/scrape/{source}
```

Realtime 交付模式会在初始 HTTP 连接上处理抓取请求。请求会一直阻塞，直到渲染、访问权限解析和解析完成，然后在响应正文中返回内容载荷。请将客户端超时时间设为至少 150 秒。

```bash
curl -X POST https://webapi.oxylabs.io/v1/scrape/amazon/product \
  -H "Authorization: Bearer $OXYLABS_WEB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "B0CX23V2ZK",
    "domain": "com",
    "output": ["json"]
  }'
```

{% hint style="info" %}
部分端点不支持 Realtime 交付（例如 YouTube 下载、ChatGPT、Gemini 和 Perplexity）。请通过 [端点发现](https://developers.oxylabs.io/products/cn/web-api/scrape/duan-dian-fa-xian.md) 确认目标是否支持，或查看 [API 参考](https://developers.oxylabs.io/api-reference).
{% endhint %}

## 单任务交付（异步）

```http
POST /v1/async/scrape/{source}
```

异步单任务交付会将抓取请求加入队列，并立即返回包含任务标识符的 HTTP `202 Accepted` 状态。

```bash
curl https://webapi.oxylabs.io/v1/async/scrape/media/youtube/metadata \
  -H "Authorization: Bearer $OXYLABS_WEB_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"query": "a1cWkClBXLI", "output": ["json"]}'
```

作业被接受后，作业 ID 会在 `metadata.request_id`.

```json
{
  "state": "pending",
  "params": { "query": "a1cWkClBXLI", "output": ["json"] },
  "metadata": { "timestamp": 1787599164, "request_id": "7497734325668954113" }
}
```

可以通过以下字段查看已提交作业的状态： `state` 结果：

<table data-header-hidden><thead><tr><th width="172"></th><th></th></tr></thead><tbody><tr><td><code>state: "pending"</code></td><td>作业正在排队或执行中。 <code>results</code> 数组仍为空（<code>[]</code>).</td></tr><tr><td><code>state: "done"</code></td><td>作业已完成。 <code>results</code> 数组包含解析后的输出。</td></tr><tr><td><code>state: "faulted"</code></td><td>提取失败。请检查 <code>results[].metadata.status_code</code> 以了解详情。</td></tr></tbody></table>

### 获取输出

可通过以下方式获取结果： [轮询](#polling-endpoint-get-v1-async-scrape-jobid), [Webhook](#webhooks-callback_url) （回调 URL），或直接 [上传到云存储](#cloud-storage-upload-storage).

#### **轮询端点（`GET /v1/async/scrape/{jobId}`)**

将数字形式的 `metadata.request_id` 传递给轮询端点。

```bash
curl -X GET https://webapi.oxylabs.io/v1/async/scrape/7497971512142465025 \
  -H "Authorization: Bearer $OXYLABS_WEB_API_KEY"
```

#### **Webhook（`callback_url`)**

在初始请求正文中加入 `callback_url` 。执行状态变为 `done` 或 `faulted`后，API 会向你指定的端点发送包含作业结果的 HTTP `POST` 负载。

```json
{
  "query": "B0CX23V2ZK",
  "output": ["json"],
  "callback_url": "https://your-api.example.com/webhooks-oxylabs"
}
```

URL 会在提交时进行验证，格式错误的 URL 将被拒绝，并返回错误 `400`.

### **云存储上传（`storage`)**

使用 `storage` 参数除了通过轮询和 Webhook 返回结果外，还会将结果写入存储桶。 **仅限异步路径** – 带有 `storage` 的实时请求会被拒绝，并返回 `400`.

```json
//POST /v1/async/scrape/amazon/product
{
  "query": "B0CX23V2ZK",
  "output": ["json"],
  "storage": {
    "type": "s3",
    "url": "s3://your-bucket-name/scraped-data"
  }
}
```

<table><thead><tr><th width="142">字段</th><th>取值</th></tr></thead><tbody><tr><td><code>storage.type</code></td><td><code>s3</code>, <code>s3_gzip</code>, <code>s3_compatible</code>, <code>gcs</code>, <code>tos</code>.</td></tr><tr><td><code>storage.url</code></td><td>存储桶和文件夹路径，不包含文件名。结果将保存为 <code>{request_id}.json</code> 并存放在所选位置。</td></tr></tbody></table>

{% hint style="warning" %}
**`storage.url` 不会经过验证。** 即使 URL 格式有效，但目标地址有误或拼写错误，系统仍会接受请求、执行任务并计费，但结果交付会失败。非 URL 格式的值会被拒绝，并返回 `400`.

**`storage.type` 会根据上方列表进行检查。** 类型无效时会返回 `400`。使用批量请求前，请先通过单个请求测试目标地址。

**`s3_gzip` 的工作方式与 `s3`** 相同，但上传的是经过 gzip 压缩的文件（`{request_id}.json.gz`).

**如果请求多种输出格式** （例如 `["json", "html"]` ），这些输出都会保存到同一个文件中。
{% endhint %}

请参阅下方的简短指南，了解如何为受支持的云存储提供商设置云存储交付：

<details>

<summary>Google Cloud Storage</summary>

```json
{
  "query": "B0CX23V2ZK",
  "output": ["json"],
  "storage": {
    "type": "gcs",
    "url": "bucket_name/path"
  }
}
```

若要允许 Oxylabs 将结果上传到您的 GCS 存储桶，请创建具有上传权限的自定义角色，并将该角色授予 Oxylabs 服务账号：

{% stepper %}
{% step %}
**创建自定义角色**

<div align="left"><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-32292235b253d2435d5e0a8d88558c068872956d%2Fgcs-1.png?alt=media" alt=""></div>
{% endstep %}

{% step %}
**输入标题（例如 `Oxylabs Uploader`），并添加 `storage.objects.create` 权限**

<div align="left"><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-815bad910c08ed706d3df43ddb20fff0f0563d6d%2Fgcs-2.png?alt=media" alt=""></div>
{% endstep %}

{% step %}
**将该角色分配给 Oxylabs**

打开 **权限** 选项卡，点击 **添加**，在 **新成员** 字段中输入以下内容 **Oxylabs 服务账号邮箱**:

```
oxyserps-storage@oxyserps-storage.iam.gserviceaccount.com
```

<div align="left"><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-df5b74908cc6943c8d620b5e14487f2d003ebe43%2Fgcs-3.png?alt=media" alt=""></div>
{% endstep %}

{% step %}
**选择** 在步骤 1 中创建的自定义角色，然后点击 **保存。**
{% endstep %}
{% endstepper %}

</details>

<details>

<summary>Amazon S3</summary>

```json
{
  "query": "B0CX23V2ZK",
  "output": ["json"],
  "storage": {
    "type": "s3",
    "url": "s3://your-bucket-name/path"
  }
}
```

如要将作业结果上传到 Amazon S3 存储桶，请为我们的服务设置访问权限。为此，请前往 [**S3 控制台**](https://s3.console.aws.amazon.com/) → **`Buckets`** → 选择您的存储桶（如果尚无存储桶，请创建一个）→ **`Permissions`** 选项卡 → **`Bucket policy`** → **`Edit`**.

<div align="left"><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-1c27676a6e925e4a8c257cf422e991c8a6a1af2c%2Fs3_bucket_policy.png?alt=media" alt=""></div>

您可以在下方或代码示例区域找到附加的存储桶策略。

{% file src="/files/613dde66c560f9f6d82fc2197d93ed7699fd0ddf" %}

请记得将 `YOUR_BUCKET_NAME`下的存储桶名称替换为您的名称。此策略允许我们向您的存储桶写入数据、让您访问已上传的文件，并获取存储桶的位置。

```json
{
    "Version": "2012-10-17",
    "Id": "Policy1577442634787",
    "Statement": [
        {
            "Sid": "Stmt1577442633719",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::324311890426:user/oxylabs.s3.uploader"
            },
            "Action": "s3:GetBucketLocation",
            "Resource": "arn:aws:s3:::YOUR_BUCKET_NAME"
        },
        {
            "Sid": "Stmt1577442633719",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::324311890426:user/oxylabs.s3.uploader"
            },
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
        }
    ]
}
```

</details>

<details>

<summary>Alibaba Cloud 对象存储服务 (OSS)</summary>

```json
{
  "query": "B0CX23V2ZK",
  "output": ["json"],
  "storage": {
    "type": "s3_compatible",
    "url": "https://ACCESS_KEY_ID:ACCESS_KEY_SECRET@BUCKET_NAME.oss-REGION.aliyuncs.com/FOLDER_NAME"
  }
}
```

#### 构造存储 URL <a href="#forming-the-storage-url" id="forming-the-storage-url"></a>

存储 URL 格式：

```http
https://ACCESS_KEY_ID:ACCESS_KEY_SECRET@BUCKET_NAME.oss-REGION.aliyuncs.com/FOLDER_NAME
```

{% hint style="warning" %}
不支持上传到存储桶根目录。 `storage.url` 必须包含文件夹名称。
{% endhint %}

您可以在此处找到 `BUCKET_NAME` 和 `oss-REGION` 存储桶的：

<figure><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-3258197766d6326f572b9230603b3f700738db36%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 创建 AccessKey 和 Secret <a href="#creating-the-access-key-and-secret" id="creating-the-access-key-and-secret"></a>

若要通过 Alibaba OSS 使用兼容 S3 的接口，必须创建 `ACCESS_KEY_ID` 和 `ACCESS_KEY_SECRET` ，如下所示。有关详细信息，请参阅 [如何使用 Amazon S3 SDK 访问 OSS](https://www.alibabacloud.com/help/en/oss/developer-reference/use-amazon-s3-sdks-to-access-oss?spm=a2c63.p38356.0.i1).

{% stepper %}
{% step %}
前往 **AccessKey 账户菜单**

<div align="left"><figure><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-7a0c00eac6fd02fed28c7be5a5522985de3625d5%2Fimage.png?alt=media" alt="" width="422"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
登录 **RAM console**

使用 [RAM console](https://ram.console.aliyun.com/) 访问 **Alibaba Cloud** 或具有管理权限的 **RAM User** 。
{% endstep %}

{% step %}
在左侧导航栏中前往 **身份** → **用户** 。
{% endstep %}

{% step %}
选择 **创建用户** 并使用 **RAM User AccessKey：**

<div align="left"><figure><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-e06b15f92c10028d2f5c368321821a90abf01f3f%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-4103046af7ce401cd189cd53f238fddf41b64ab5%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**为 RAM 用户授予权限**

新创建的 RAM 用户没有任何权限。您必须向该 RAM 用户授予 **AliyunOSSFullAccess** 权限。之后，该 RAM 用户便可访问所需的 Alibaba Cloud 资源。有关详细信息，请参阅 [为 RAM 用户授予权限](https://www.alibabacloud.com/help/en/ram/user-guide/grant-permissions-to-the-ram-user#task-187800).

<div align="left"><figure><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-6d76a9af42bd9f8eaabdbee6c4baadd5824a0a09%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
获取您的 **AccessKey ID** 和 **AccessKey Secret**

授予权限后，返回 **身份验证** 部分，然后在 **Access Key** 部分中选择 **创建 AccessKey**。选择为 **第三方服务**创建 Access Key。随后，您将看到一个 `ACCESS_KEY_ID` 和 `ACCESS_KEY_SECRET`，然后即可在请求中使用。
{% endstep %}
{% endstepper %}

#### 阿里云 OSS 速率限制 <a href="#alibaba-oss-ratelimits" id="alibaba-oss-ratelimits"></a>

向阿里云 OSS 并发上传时，可能会触发账号或存储桶的速率限制，导致上传开始超时并出现以下错误：

<div align="left"><figure><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-8c6734c7968642444e43843fb1f200f0ab739c81%2Fimage.png?alt=media" alt="" width="563"><figcaption></figcaption></figure></div>

遇到这种情况，请联系阿里云 OSS 支持团队提高 OSS 速率限制。

</details>

<details>

<summary>BytePlus Torch 对象存储 (TOS)</summary>

要成功连接，您需要：

* 配置正确的 TOS 存储桶。
* 您的访问密钥和密钥。
* 与 S3 兼容的端点。

您可以在 BytePlus 官方 [文档](https://docs.byteplus.com/en/docs/tos/docs-region-and-endpoint).

以下负载会将结果上传到您的 TOS 存储桶，并将结果保存为\
`{request_id}.json` ，存放在您指定的路径中：

```json
{
  "query": "B0CX23V2ZK",
  "output": ["json"],
  "storage": {
    "type": "tos",
    "url": "https://ACCESS_KEY:SECRET_KEY@ENDPOINT/BUCKET_NAME/PATH"
  }
}
```

#### 存储 URL 格式

&#x20;`storage.url` 必须使用您的 TOS 凭据和存储桶信息构造。

```bash
https://access_key:secret_key@endpoint/bucket_name/path
```

| 组件            | 说明                                            |
| ------------- | --------------------------------------------- |
| `access_key`  | 您的 BytePlus 访问密钥 ID。                          |
| `secret_key`  | 您的 BytePlus 访问密钥。                             |
| `endpoint`    | 特定区域的端点（例如 `tos-cn-hongkong.bytepluses.com`). |
| `bucket_name` | 目标存储桶名称。                                      |
| `path`        | *（可选）* 存储桶中的特定文件夹路径。                          |

{% hint style="warning" %}
如果您的访问密钥或密钥包含特殊字符（例如 `/`, `+`或 `=`），则 **必须进行 URL 编码** 然后再构造字符串。
{% endhint %}

</details>

<details>

<summary>其他兼容 S3 的存储</summary>

如果您希望将结果发送到与 S3 兼容的存储位置，则需要在负载的 `ACCESS_KEY:SECRET` 中包含存储桶的身份验证字符串，并将其设为 `storage.url` 的值：

```json
{
  "query": "B0CX23V2ZK",
  "output": ["json"],
  "storage": {
    "type": "s3_compatible",
    "url": "https://ACCESS_KEY:SECRET@HOST/BUCKET_PATH"
  }
}
```

1. 在存储提供商的控制台中， **创建访问密钥和密钥** 可以写入目标存储桶。
2. 构建 `storage.url` 根据你的值构建：
   * `ACCESS_KEY`：你的访问密钥。
   * `SECRET`：你的密钥。
   * `HOST`：你的提供商的 S3 终端节点主机。
   * `BUCKET_PATH`：存储桶名称，可选附加文件夹路径。

示例： `https://ACCESS_KEY:SECRET@s3.example.com/my-bucket/results`

</details>

## 批量投递（异步）

{% hint style="warning" %}
批量路由仅适用于部分 `/scrape` 来源。请通过 [端点发现](https://developers.oxylabs.io/products/cn/web-api/scrape/duan-dian-fa-xian.md) 确认目标是否符合条件，或查看 [API 参考](https://developers.oxylabs.io/api-reference).
{% endhint %}

```http
POST /v1/async/scrape/batch/{source}
```

批量投递可在单个 HTTP 请求中提交最多 5,000 个抓取任务。输入字段不再接受单个 `url` 或 `query` 字符串，而是接受字符串数组。负载中的其他所有字段都会应用于批次中的每个任务。

```bash
curl -X POST https://webapi.oxylabs.io/v1/async/scrape/batch/amazon/product \
  -H "Authorization: Bearer $OXYLABS_WEB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": ["B0CX23V2ZK", "B09B33PQS9", "INVALID_ASIN_XYZ"],
    "domain": "com",
    "output": ["json"]
  }'
```

批量端点会返回 HTTP `202 Accepted` 状态，并在 `data[]` 中包含各个任务状态的数组，同时还会返回 `errors[]` 数组，列出被拒绝的项目（例如，ASIN 格式无效或 URL 语法无效）。请参见以下示例：

<details>

<summary>输出示例</summary>

```json
{
  "data": [
    {
      "state": "pending",
      "params": {
        "query": "B0CX23V2ZK",
        "output": [
          "json"
        ],
        "json": {
          "schema": null,
          "prompt": null
        },
        "location": null,
        "device": "desktop",
        "run_js": null,
        "storage": {
          "type": null,
          "url": null
        },
        "callback_url": null,
        "client_notes": null,
        "domain": "com",
        "locale": null,
        "autoselect_variant": false,
        "check_empty_geo": null,
        "safe_search": true,
        "currency": null
      },
      "metadata": {
        "timestamp": 1790852882,
        "request_id": "7511381408825235457"
      }
    },
    {
      "state": "pending",
      "params": {
        "query": "B09B33PQS9",
        "output": [
          "json"
        ],
        "json": {
          "schema": null,
          "prompt": null
        },
        "location": null,
        "device": "desktop",
        "run_js": null,
        "storage": {
          "type": null,
          "url": null
        },
        "callback_url": null,
        "client_notes": null,
        "domain": "com",
        "locale": null,
        "autoselect_variant": false,
        "check_empty_geo": null,
        "safe_search": true,
        "currency": null
      },
      "metadata": {
        "timestamp": 1790852882,
        "request_id": "7511381408825229313"
      }
    }
  ],
  "errors": [
    {
      "detail": "ASIN should only contain alphanumeric values.",
      "pointer": "/query/2"
    }
  ]
}
```

</details>


---

# 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/jiao-fu-mo-shi.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.
