> ## 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.

# 同期スクレイピング

> `scrape` エンドポイントはブラウザセッションを実行し、JavaScript を実行して、1 回の同期リクエストでレンダリング済み HTML を返します。

## はじめに

### ベース URL

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

### リクエスト例

```bash theme={"system"}
curl -X POST 'https://scrape.cleariflow.com/v1/scrape' \
  -H 'Content-Type: application/json' \
  -d '{
    "api_key": "YOUR_UNIQUE_API_KEY",
    "url": "https://example.com",
    "render": {
      "wait_until": "networkidle",
      "timeout_ms": 60000
    }
  }'
```

成功したリクエストはレンダリング済みページ HTML とメタデータを返します：

<ResponseExample>
  ```json theme={"system"}
  {
    "ok": true,
    "html": "<!DOCTYPE html><html>...</html>",
    "meta": {
      "elapsed_ms": 4521
    }
  }
  ```
</ResponseExample>

### レンダリングオプション

`render` オブジェクトは HTML 取得前のページ読み込み方法を制御します。すべてのフィールドは任意で、省略時はサーバーのデフォルト値が適用されます。

```json theme={"system"}
"render": {
  "wait_until": "networkidle",
  "timeout_ms": 60000,
  "post_load_wait_ms": 2000,
  "ignore_https_errors": false
}
```

| フィールド                 | 型       | デフォルト              | 説明                                                                                               |
| --------------------- | ------- | ------------------ | ------------------------------------------------------------------------------------------------ |
| `wait_until`          | String  | `domcontentloaded` | ナビゲーション完了とみなすタイミング。高速な結果には `domcontentloaded`、初期 HTML 後に XHR/fetch でデータを読み込むページには `networkidle`。 |
| `timeout_ms`          | Integer | `60000`            | ページ読み込みの最大待機時間（ミリ秒）。超過するとリクエストは失敗します。                                                            |
| `post_load_wait_ms`   | Integer | `0`                | `wait_until` 後、HTML 取得前の追加待機時間（ミリ秒）。アニメーション、lazy-load ウィジェット、`networkidle` 後のクライアント側レンダリングに有用。   |
| `ignore_https_errors` | Boolean | `false`            | `true` の場合、対象ページの TLS 証明書エラーを無視します。                                                              |

読み込み後もデータ取得を続ける JavaScript 多用ページの例:

```bash theme={"system"}
curl -X POST 'https://scrape.cleariflow.com/v1/scrape' \
  -H 'Content-Type: application/json' \
  -d '{
    "api_key": "YOUR_UNIQUE_API_KEY",
    "url": "https://quotes.toscrape.com/js/",
    "render": {
      "wait_until": "networkidle",
      "timeout_ms": 60000,
      "post_load_wait_ms": 1500,
      "ignore_https_errors": false
    }
  }'
```

### リソースオプション

`resources` オブジェクトはスクレイピング中にブラウザが読み込むアセット種別を制御します。HTML のテキストと構造だけが必要な場合、重いリソースをブロックするとリクエストが高速化されます。

```json theme={"system"}
"resources": {
  "block": ["images", "fonts", "media"]
}
```

| 値        | ブロック対象                                  |
| -------- | --------------------------------------- |
| `images` | 画像（`<img>`、CSS 背景、画像として読み込まれる SVG アイコン） |
| `fonts`  | Web フォント                                |
| `media`  | 動画・音声ストリーム                              |

すべてのフィールドは任意です。`resources` を省略した場合、デプロイメントでサーバー側デフォルトが設定されていない限り、リソース種別はブロックされません。

例 — 画像とフォントをスキップして高速化:

```bash theme={"system"}
curl -X POST 'https://scrape.cleariflow.com/v1/scrape' \
  -H 'Content-Type: application/json' \
  -d '{
    "api_key": "YOUR_UNIQUE_API_KEY",
    "url": "https://quotes.toscrape.com/",
    "resources": {
      "block": ["images", "fonts"]
    }
  }'
```

### リクエストパラメータ

<ParamField body="url" type="String" required>
  スクレイピング対象 URL。公開 HTTP または HTTPS URL である必要があります。localhost およびプライベート IP へのリクエストは SSRF 保護によりブロックされます。
</ParamField>

<ParamField body="api_key" type="String" required>
  固有の API キー。
</ParamField>

<ParamField body="session_id" type="String">
  複数のスクレイピングリクエスト間でブラウザ状態（Cookie、ローカルストレージ）を再利用するためのオプションのセッション ID。
</ParamField>

<ParamField body="fingerprint" type="String">
  ブラウザフィンガープリントプリセット。対応値: `desktop_en_us`、`desktop_ru_ru`、`mobile_en_us`。
</ParamField>

<ParamField body="render" type="Object">
  ブラウザセッションのレンダリングオプション。
</ParamField>

<ParamField body="render.wait_until" type="String">
  ナビゲーション完了とみなすタイミング。値: `domcontentloaded`、`networkidle`。デフォルト: `domcontentloaded`。
</ParamField>

<ParamField body="render.timeout_ms" type="Integer">
  ページ読み込み待機の最大時間（ミリ秒）。デフォルト: 60000。
</ParamField>

<ParamField body="render.post_load_wait_ms" type="Integer">
  ページ読み込み後、コンテンツ取得前の追加待機時間（ミリ秒）。
</ParamField>

<ParamField body="render.ignore_https_errors" type="Boolean">
  `true` の場合、ターゲットページの TLS 証明書エラーを無視します。
</ParamField>

<ParamField body="resources" type="Object">
  リソース読み込みの制御。
</ParamField>

<ParamField body="resources.block" type="Array">
  ブロックするリソースタイプ。対応値: `images`、`fonts`、`media`。
</ParamField>

<ParamField body="actions" type="Array">
  コンテンツ取得前に実行するブラウザアクションの順序付きリスト。各アクションは `type` フィールドを持つオブジェクトです。
</ParamField>

<ParamField body="actions[].type" type="String" required>
  アクションタイプ。対応値: `wait`、`wait_for`、`click`、`type`、`scroll`。
</ParamField>

<ParamField body="actions[].selector" type="String">
  `wait_for`、`click`、`type` アクション用の CSS セレクタ。
</ParamField>

<ParamField body="actions[].text" type="String">
  `type` アクションで入力するテキスト。
</ParamField>

<ParamField body="actions[].to" type="String">
  `scroll` アクションのスクロール先（例: `bottom`）。
</ParamField>

<ParamField body="actions[].wait_ms" type="Integer">
  `wait` アクションの待機時間（ミリ秒）。
</ParamField>

<ParamField body="actions[].timeout_ms" type="Integer">
  `wait_for` アクションのタイムアウト（ミリ秒）。
</ParamField>

<ParamField body="cookies" type="Array">
  ナビゲーション前に注入する Cookie。各 Cookie オブジェクトには `name` と `value` が必要。オプション: `domain`、`path`。
</ParamField>

### レスポンスパラメータ

API レスポンスは汎用的で軽量な [JSON 形式](https://www.json.org/json-en.html)で返されます。

<ResponseField name="ok" type="Boolean">
  スクレイピングが正常に完了したかどうか。
</ResponseField>

<ResponseField name="html" type="String">
  レンダリング済みページ HTML。
</ResponseField>

<ResponseField name="meta" type="Object">
  最終 URL、HTTP ステータスコード、処理時間などのスクレイピングメタデータ。
</ResponseField>

<ResponseField name="error" type="Object">
  `ok` が `false` の場合のエラー詳細。
</ResponseField>
