> ## Documentation Index
> Fetch the complete documentation index at: https://germeytechnology-docs-remove-4o-image-nav.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# WebExtrator 網頁渲染 API 集成指南

> WebExtrator Web Render & Extract 集成指南 - Ace Data Cloud

`POST https://api.acedata.cloud/webextrator/render`

## 鑑權

請求頭加入 `Authorization: Bearer &lt;你的 API Key>`。

## 請求參數

| 欄位                  | 類型        |  必填 | 預設     | 說明                                             |
| ------------------- | --------- | :-: | ------ | ---------------------------------------------- |
| `url`               | string    |  ✅  | -      | 要渲染的頁面 URL                                     |
| `user_agent`        | string    |  ❌  | 系統預設   | 自訂 User-Agent                                  |
| `timeout`           | number    |  ❌  | 30000  | 單次渲染逾時（毫秒），最大 120000                           |
| `wait_until`        | string    |  ❌  | `load` | 載入完成事件：`load`/`domcontentloaded`/`networkidle` |
| `delay`             | number    |  ❌  | 0      | 載入完成後再等待的時間（毫秒），最大 30000                       |
| `wait_for_selector` | string    |  ❌  | -      | 等待該 CSS 選擇器出現                                  |
| `block_resources`   | string\[] |  ❌  | -      | 屏蔽資源類型：`image`/`media`/`font`/`stylesheet` 等   |
| `headers`           | object    |  ❌  | -      | 額外 HTTP 頭                                      |
| `cookies`           | array     |  ❌  | -      | Cookie 列表，元素形如 `{name, value, domain, path}`   |
| `callback_url`      | string    |  ❌  | -      | 非同步模式回調地址；提供則立即返回任務 ID，結果透過 POST 回調            |

## 同步回應（不帶 callback\_url）

```json theme={null}
{
  "success": true,
  "task_id": "550e8400-e29b-41d4-a716-446655440000",
  "trace_id": "550e8400-e29b-41d4-a716-446655440001",
  "started_at": "2026-05-02T10:30:00.123Z",
  "finished_at": "2026-05-02T10:30:05.456Z",
  "elapsed": 5.333,
  "data": {
    "kind": "render",
    "url": "https://example.com",
    "title": "Example Domain",
    "html": "<!doctype html>...",
    "text": "Example Domain ...",
    "markdown": "# Example Domain\n...",
    "screenshot": "data:image/png;base64,iVBORw0K...",
    "links": ["https://www.iana.org/domains/example"]
  }
}
```

## 非同步模式（帶 callback\_url）

初始回應：

```json theme={null}
{
  "success": true,
  "task_id": "550e8400-e29b-41d4-a716-446655440000",
  "trace_id": "550e8400-e29b-41d4-a716-446655440001",
  "started_at": "2026-05-02T10:30:00.123Z"
}
```

回應頭會包含 `x-usage-exempt: true`，表示這次同步握手不扣費。任務真正完成後，平台會向 `callback_url` 發送一次 POST，請求體即同步回應中的 `data` 欄位加上同樣的 `task_id` / `trace_id` / `started_at` / `finished_at` / `elapsed` 欄位。

## 錯誤回應

```json theme={null}
{
  "success": false,
  "task_id": "550e8400-e29b-41d4-a716-446655440000",
  "trace_id": "550e8400-e29b-41d4-a716-446655440001",
  "started_at": "2026-05-02T10:30:00.123Z",
  "error": {
    "code": "timeout",
    "message": "page load timed out after 30000ms"
  }
}
```

錯誤碼：`bad_request` / `forbidden` / `too_many_requests` / `not_found` / `api_error` / `timeout` / `unknown` / `busy`。

## 範例

```bash theme={null}
curl -X POST https://api.acedata.cloud/webextrator/render \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "wait_until": "networkidle",
    "block_resources": ["image", "media", "font"]
  }'
```
