> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cleariflow.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 异步任务

> `jobs` 端点将抓取任务加入队列，并允许轮询状态和结果 — 适合高并发或加载较慢的页面。

## 入门

### 基础 URL

```
https://scrape.cleariflow.com/v1/jobs
```

## 创建任务

使用与同步端点相同的 `ScrapeRequest` 负载将异步抓取任务入队。

### 请求示例

```bash theme={"system"}
curl -X POST 'https://scrape.cleariflow.com/v1/jobs' \
  -H 'Content-Type: application/json' \
  -d '{
    "request": {
      "api_key": "YOUR_UNIQUE_API_KEY",
      "url": "https://example.com"
    },
    "priority": 10
  }'
```

成功请求返回任务 ID：

<ResponseExample>
  ```json theme={"system"}
  {
    "job_id": "550e8400-e29b-41d4-a716-446655440000"
  }
  ```
</ResponseExample>

### 创建任务参数

<ParamField body="request" type="Object" required>
  与同步抓取端点字段相同的 `ScrapeRequest` 对象（`url`、`render`、`actions`、`cookies` 等）。
</ParamField>

<ParamField body="priority" type="Integer">
  任务优先级。数值越高越先处理。默认：0。
</ParamField>

## 获取任务状态

通过 ID 轮询任务以检查状态，并在完成后获取结果。

### 基础 URL

```
https://scrape.cleariflow.com/v1/jobs/{job_id}
```

### 请求示例

```bash theme={"system"}
curl 'https://scrape.cleariflow.com/v1/jobs/550e8400-e29b-41d4-a716-446655440000'
```

任务运行中：

<ResponseExample>
  ```json theme={"system"}
  {
    "job_id": "550e8400-e29b-41d4-a716-446655440000",
    "status": "running"
  }
  ```
</ResponseExample>

任务成功完成时：

<ResponseExample>
  ```json theme={"system"}
  {
    "job_id": "550e8400-e29b-41d4-a716-446655440000",
    "status": "done",
    "result": {
      "ok": true,
      "html": "<!DOCTYPE html><html>...</html>",
      "meta": {
        "elapsed_ms": 8123
      }
    }
  }
  ```
</ResponseExample>

### 任务状态值

| 状态        | 说明                   |
| --------- | -------------------- |
| `queued`  | 任务在队列中等待。            |
| `running` | 浏览器会话活跃中。            |
| `done`    | 抓取完成；`result` 包含输出。  |
| `failed`  | 抓取失败；`error` 包含错误描述。 |

### 响应参数

<ResponseField name="job_id" type="String">
  异步任务的唯一标识符。
</ResponseField>

<ResponseField name="status" type="String">
  当前任务状态：`queued`、`running`、`done` 或 `failed`。
</ResponseField>

<ResponseField name="result" type="Object">
  抓取结果对象（与同步端点响应结构相同）。当 `status` 为 `done` 时返回。
</ResponseField>

<ResponseField name="error" type="String">
  错误消息。当 `status` 为 `failed` 时返回。
</ResponseField>

<ResponseField name="meta" type="Object">
  有关任务执行的额外元数据。
</ResponseField>
