> ## Documentation Index
> Fetch the complete documentation index at: https://student-213fb9fc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# バッチスクレイピング

> 複数のURLをバッチでスクレイピングする

<div id="batch-scraping-multiple-urls">
  ## 複数のURLを一括スクレイピング
</div>

複数のURLを同時に一括スクレイピングできます。開始URLと任意のパラメータを引数に取ります。params 引数では、出力フォーマットなど、一括スクレイピングジョブの追加オプションを指定できます。

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

`/crawl` エンドポイントの動作とほぼ同じです。バッチを開始して完了まで待つことも、開始して完了処理を自分で行うこともできます。

* `batchScrape`（JS）/ `batch_scrape`（Python）：バッチジョブを開始し、完了まで待って結果を返します。
* `startBatchScrape`（JS）/ `start_batch_scrape`（Python）：バッチジョブを開始し、ポーリングやウェブフックに使えるジョブIDを返します。

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

デフォルトでは、バッチスクレイプジョブはチームのブラウザ同時実行数の上限をフルに使用します（[Rate Limits](/ja/rate-limits) を参照）。`maxConcurrency` パラメータでジョブごとにこの上限を下げることができます。たとえば、`maxConcurrency: 50` とすると、そのジョブは同時に 50 件までしかスクレイプを実行しません。大規模なバッチでこの値を低くしすぎると処理が大幅に遅くなるため、他のジョブ用に同時実行枠を残す必要がある場合にのみ減らしてください。

<div id="usage">
  ### 使い方
</div>

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

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

  start = firecrawl.start_batch_scrape([
      "https://firecrawl.dev",
      "https://docs.firecrawl.dev",
  ], formats=["markdown"])  # 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 '@mendable/firecrawl-js';

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

  // バッチスクレイプのジョブを開始
  const { id } = await firecrawl.startBatchScrape([
    'https://firecrawl.dev',
    'https://docs.firecrawl.dev'
  ], {
    options: { formats: ['markdown'] },
  });

  // 完了まで待機
  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="batch-scrape-with-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 '@mendable/firecrawl-js';

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

  // 抽出先となるスキーマを定義
  const schema = {
    type: "object",
    properties: {
      title: { type: "string" },
      description: { type: "string" }
    },
    required: ["title", "description"]
  };

  // 複数サイトをスクレイプ（同期）:
  const batchScrapeResult = await firecrawl.batchScrape(['https://docs.firecrawl.dev', 'https://docs.firecrawl.dev/sdks/overview'], { 
    formats: [
      {
        type: "json",
        prompt: "ページからタイトルと概要を抽出してください。",
        schema: schema
      }
    ]
  });

  // バッチスクレイプの結果をすべて出力:
  console.log(batchScrapeResult)

  // あるいは start メソッドを使うこともできます:
  const batchScrapeJob = await firecrawl.startBatchScrape(['https://docs.firecrawl.dev', 'https://docs.firecrawl.dev/sdks/overview'], { 
    formats: [
      {
        type: "json",
        prompt: "ページからタイトルと概要を抽出してください。",
        schema: schema
      }
    ]
  });
  console.log(batchScrapeJob)

  // その後、ジョブ ID でバッチスクレイプのステータスを確認できます:
  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="batch-scrape-with-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="quick-reference">
  ### クイックリファレンス
</div>

**イベントタイプ:**

* `batch_scrape.started` - バッチスクレイプが開始されたとき
* `batch_scrape.page` - 各URLのスクレイプに成功したとき
* `batch_scrape.completed` - すべてのURLの処理が完了したとき
* `batch_scrape.failed` - バッチスクレイプでエラーが発生した場合

**基本ペイロード:**

```json theme={null}
{
  "success": true,
  "type": "batch_scrape.page",
  "id": "batch-job-id",
  "data": [...], // 'page'イベントのページデータ
  "metadata": {}, // Your custom metadata
  "error": null
}
```

<div id="security-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) を参照してください。

<div id="full-documentation">
  ### 詳細なドキュメント
</div>

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