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

# バッチスクレイピング

> 単一のバッチジョブで複数のURLをスクレイピングする

バッチスクレイピングでは、1つのジョブで複数のURLをスクレイピングできます。URLのリストと任意のパラメータを渡すと、Firecrawl がそれらを並行して処理し、すべての結果をまとめて返します。

* 明示的に指定したURLのリストを対象とする点を除き、`/crawl` と同様に動作します
* 同期モードと非同期モードに対応
* 構造化抽出を含む、すべてのスクレイピングオプションをサポート
* ジョブごとに同時実行数を設定可能

<div id="how-it-works">
  ## 仕組み
</div>

バッチスクレイプは、次の2つの方法で実行できます。

| モード | SDK メソッド (JS / Python)                    | 動作                                      |
| --- | ----------------------------------------- | --------------------------------------- |
| 同期  | `batchScrape` / `batch_scrape`            | バッチを開始し、完了まで待機して、すべての結果を返します            |
| 非同期 | `startBatchScrape` / `start_batch_scrape` | バッチを開始し、ポーリングまたは Webhook 用のジョブ ID を返します |

<div id="basic-usage">
  ## 基本的な使い方
</div>

<CodeGroup>
  ```python Python theme={null}
  from firecrawl import Firecrawl

  firecrawl = Firecrawl(api_key="fc-YOUR-API-KEY")

  # 非同期: バッチを開始し、ジョブIDを即座に返す
  start = firecrawl.start_batch_scrape([
      "https://firecrawl.dev",
      "https://docs.firecrawl.dev",
  ], formats=["markdown"])

  status = firecrawl.get_batch_scrape_status(start.id)

  # または同期: バッチを開始し、完了まで待機する
  job = firecrawl.batch_scrape([
      "https://firecrawl.dev",
      "https://docs.firecrawl.dev",
  ], formats=["markdown"], poll_interval=2, wait_timeout=120)

  print(job.status, job.completed, job.total)
  ```

  ```js Node theme={null}
  import { Firecrawl } from 'firecrawl';

  const firecrawl = new Firecrawl({ apiKey: "fc-YOUR-API-KEY" });

  // 非同期: バッチを開始し、ジョブIDをすぐに返す
  const { id } = await firecrawl.startBatchScrape([
    'https://firecrawl.dev',
    'https://docs.firecrawl.dev'
  ], {
    options: { formats: ['markdown'] },
  });

  const status = await firecrawl.getBatchScrapeStatus(id);

  // または同期: バッチを開始し、完了まで待機
  const job = await firecrawl.batchScrape([
    'https://firecrawl.dev',
    'https://docs.firecrawl.dev'
  ], { options: { formats: ['markdown'] }, pollInterval: 2, timeout: 120 });

  console.log(job.status, job.completed, job.total);
  ```

  ```bash cURL theme={null}
  curl -s -X POST "https://api.firecrawl.dev/v2/batch/scrape" \
    -H "Authorization: Bearer $FIRECRAWL_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "urls": ["https://firecrawl.dev", "https://docs.firecrawl.dev"],
      "formats": ["markdown"]
    }'
  ```
</CodeGroup>

<div id="response">
  ### レスポンス
</div>

`batchScrape` / `batch_scrape` を呼び出すと、バッチ完了時に完全な結果が返されます。

```json 完了 theme={null}
{
  "status": "completed",
  "total": 36,
  "completed": 36,
  "creditsUsed": 36,
  "expiresAt": "2024-00-00T00:00:00.000Z",
  "next": "https://api.firecrawl.dev/v2/batch/scrape/123-456-789?skip=26",
  "data": [
    {
      "markdown": "[Firecrawl Docs のホームページ![light logo](https://mintlify.s3-us-west-1.amazonaws.com/firecrawl/logo/light.svg)!...",
      "html": "<!DOCTYPE html><html lang=\"en\" class=\"js-focus-visible lg:[--scroll-mt:9.5rem]\" data-js-focus-visible=\"\">...",
      "metadata": {
        "title": "Groq Llama 3 で「ウェブサイトと会話できる」機能を構築する | Firecrawl",
        "language": "en",
        "sourceURL": "https://docs.firecrawl.dev/learn/rag-llama3",
        "description": "Firecrawl、Groq Llama 3、LangChain を使って「自分のウェブサイトと会話できる」ボットを構築する方法を学びます。",
        "ogLocaleAlternate": [],
        "statusCode": 200
      }
    },
    ...
  ]
}
```

`startBatchScrape` / `start_batch_scrape` を呼び出すと、`getBatchScrapeStatus` / `get_batch_scrape_status`、API エンドポイント `/batch/scrape/{id}`、または Webhook を使って追跡できるジョブ ID が返されます。ジョブの結果は、完了後 24 時間まで API 経由で取得できます。この期間を過ぎても、[activity logs](https://www.firecrawl.dev/app/logs) からバッチスクレイプの履歴と結果を確認できます。

```json theme={null}
{
  "success": true,
  "id": "123-456-789",
  "url": "https://api.firecrawl.dev/v2/batch/scrape/123-456-789"
}
```

<div id="concurrency">
  ## 並行実行数
</div>

デフォルトでは、バッチスクレイプジョブはチームのブラウザ同時実行数の上限をフルに使用します ([Rate Limits](/ja/rate-limits) を参照) 。`maxConcurrency` パラメータでジョブごとにこの上限を下げることができます。

たとえば、`maxConcurrency: 50` とすると、そのジョブは同時に 50 件までしかスクレイプを実行しません。大規模なバッチでこの値を低くしすぎると処理が大幅に遅くなるため、他のジョブ用に同時実行枠を残す必要がある場合にのみ減らしてください。

<div id="structured-extraction">
  ## 構造化抽出
</div>

バッチスクレイプを使用して、バッチ内のすべてのページから構造化データを抽出できます。これは、URLのリストに同じスキーマを適用したい場合に便利です。

<CodeGroup>
  ```python Python theme={null}
  from firecrawl import Firecrawl

  firecrawl = Firecrawl(api_key="fc-YOUR_API_KEY")

  # 複数のサイトをスクレイプします：
  batch_scrape_result = firecrawl.batch_scrape(
      ['https://docs.firecrawl.dev', 'https://docs.firecrawl.dev/sdks/overview'], 
      formats=[{
          'type': 'json',
          'prompt': 'ページのタイトルと説明を抽出してください。',
          'schema': {
              'type': 'object',
              'properties': {
                  'title': {'type': 'string'},
                  'description': {'type': 'string'}
              },
              'required': ['title', 'description']
          }
      }]
  )
  print(batch_scrape_result)

  # あるいは start メソッドを使うこともできます：
  batch_scrape_job = firecrawl.start_batch_scrape(
      ['https://docs.firecrawl.dev', 'https://docs.firecrawl.dev/sdks/overview'], 
      formats=[{
          'type': 'json',
          'prompt': 'ページのタイトルと説明を抽出してください。',
          'schema': {
              'type': 'object',
              'properties': {
                  'title': {'type': 'string'},
                  'description': {'type': 'string'}
              },
              'required': ['title', 'description']
          }
      }]
  )
  print(batch_scrape_job)

  # その後、ジョブIDでバッチスクレイプのステータスを確認できます：
  batch_scrape_status = firecrawl.get_batch_scrape_status(batch_scrape_job.id)
  print(batch_scrape_status)
  ```

  ```js Node theme={null}
  import { Firecrawl, ScrapeResponse } from 'firecrawl';

  const firecrawl = new Firecrawl({apiKey: "fc-YOUR_API_KEY"});

  // Define schema to extract contents into
  const schema = {
    type: "object",
    properties: {
      title: { type: "string" },
      description: { type: "string" }
    },
    required: ["title", "description"]
  };

  // Scrape multiple websites (synchronous):
  const batchScrapeResult = await firecrawl.batchScrape(['https://docs.firecrawl.dev', 'https://docs.firecrawl.dev/sdks/overview'], { 
    formats: [
      {
        type: "json",
        prompt: "Extract the title and description from the page.",
        schema: schema
      }
    ]
  });

  // Output all the results of the batch scrape:
  console.log(batchScrapeResult)

  // Or, you can use the start method:
  const batchScrapeJob = await firecrawl.startBatchScrape(['https://docs.firecrawl.dev', 'https://docs.firecrawl.dev/sdks/overview'], { 
    formats: [
      {
        type: "json",
        prompt: "Extract the title and description from the page.",
        schema: schema
      }
    ]
  });
  console.log(batchScrapeJob)

  // You can then use the job ID to check the status of the batch scrape:
  const batchScrapeStatus = await firecrawl.getBatchScrapeStatus(batchScrapeJob.id);
  console.log(batchScrapeStatus)
  ```

  ```bash cURL theme={null}
  curl -X POST https://api.firecrawl.dev/v2/batch/scrape \
      -H 'Content-Type: application/json' \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      -d '{
        "urls": ["https://docs.firecrawl.dev", "https://docs.firecrawl.dev/sdks/overview"],
        "formats" : [{
          "type": "json",
          "prompt": "ページからタイトルと説明を抽出してください。",
          "schema": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string"
              },
              "description": {
                "type": "string"
              }
            },
            "required": [
              "title",
              "description"
            ]
          }
        }]
      }'
  ```
</CodeGroup>

<div id="response">
  ### レスポンス
</div>

`batchScrape` / `batch_scrape` は完全な結果を返します：

```json 完了 theme={null}
{
  "status": "completed",
  "total": 36,
  "completed": 36,
  "creditsUsed": 36,
  "expiresAt": "2024-00-00T00:00:00.000Z",
  "next": "https://api.firecrawl.dev/v2/batch/scrape/123-456-789?skip=26",
  "data": [
    {
      "json": {
        "title": "Build a 'Chat with website' using Groq Llama 3 | Firecrawl",
        "description": "Firecrawl、Groq Llama 3、LangChain を使って「自分のウェブサイトとチャットできる」ボットの作り方を解説します。"
      }
    },
    ...
  ]
}
```

`startBatchScrape` / `start_batch_scrape` はジョブ ID を返します：

```json theme={null}
{
  "success": true,
  "id": "123-456-789",
  "url": "https://api.firecrawl.dev/v2/batch/scrape/123-456-789"
}
```

<div id="webhooks">
  ## Webhooks
</div>

バッチ内の各 URL がスクレイプされるたびにリアルタイムで通知を受け取れるよう、webhook を設定できます。これにより、バッチ全体の完了を待たずに結果を即時に処理できます。

```bash cURL theme={null}
curl -X POST https://api.firecrawl.dev/v2/batch/scrape \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -d '{
      "urls": [
        "https://example.com/page1",
        "https://example.com/page2",
        "https://example.com/page3"
      ],
      "webhook": {
        "url": "https://your-domain.com/webhook",
        "metadata": {
          "any_key": "any_value"
        },
        "events": ["started", "page", "completed"]
      }
    }'
```

<div id="event-types">
  ### イベントの種類
</div>

| イベント                     | 説明                     |
| ------------------------ | ---------------------- |
| `batch_scrape.started`   | バッチスクレイプジョブが開始されました    |
| `batch_scrape.page`      | 1件のURLのスクレイプに成功しました    |
| `batch_scrape.completed` | すべてのURLの処理が完了しました      |
| `batch_scrape.failed`    | バッチスクレイプジョブでエラーが発生しました |

<div id="payload">
  ### ペイロード
</div>

各Webhook配信には、次の構造のJSONボディが含まれます:

```json theme={null}
{
  "success": true,
  "type": "batch_scrape.page",
  "id": "batch-job-id",
  "data": [...],
  "metadata": {},
  "error": null
}
```

<div id="verifying-webhook-signatures">
  ### Webhook シグネチャの検証
</div>

Firecrawl から送信されるすべての webhook リクエストには、HMAC-SHA256 シグネチャを含む `X-Firecrawl-Signature` ヘッダーが含まれます。Webhook が正当なものであり、改ざんされていないことを確認するために、必ずこのシグネチャを検証してください。

1. アカウント設定の [Advanced タブ](https://www.firecrawl.dev/app/settings?tab=advanced) から webhook secret を取得する
2. `X-Firecrawl-Signature` ヘッダーからシグネチャを取り出す
3. secret を使って、生のリクエストボディに対して HMAC-SHA256 を計算する
4. タイミング攻撃耐性のある (タイミングセーフな) 関数を用いて、計算結果とシグネチャヘッダーを比較する

<Warning>
  シグネチャを事前に検証せずに webhook を処理しないでください。`X-Firecrawl-Signature` ヘッダーには、`sha256=abc123def456...` という形式でシグネチャが含まれています。
</Warning>

JavaScript と Python による実装の完全な例については、[Webhook セキュリティのドキュメント](/ja/webhooks/security) を参照してください。

詳細なイベントペイロード、高度な設定、トラブルシューティングなどを含む webhook の包括的なドキュメントについては、[Webhooks ドキュメント](/ja/webhooks/overview) を参照してください。

> Firecrawl API key が必要な AI agent の方は、自動オンボーディング手順について [firecrawl.dev/agent-onboarding/SKILL.md](https://www.firecrawl.dev/agent-onboarding/SKILL.md) を参照してください。
