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

# ChatGPT 爬虫快速入门

> 在5分钟内设置Bright Data ChatGPT爬虫API并使用您的第一个提示搜索ChatGPT。

# 中文翻译

本教程展示了如何向 ChatGPT 发送搜索提示，并使用 Bright Data ChatGPT Scraper API 获取结构化 JSON 数据。

## 前置条件

* 一个 [Bright Data 账户](https://www.bright.cn/products/web-scraper/chatgpt?hs_signup=1\&utm_source=docs)（每月含 5,000 个免费积分）
* 已安装 cURL、Python 3.9+ 或 Node.js 18+

<Steps>
  <Step title="获取您的 API 密钥">
    转到您 Bright Data 账户中的[用户设置页面](https://www.bright.cn/cp/setting/users)并创建一个 API 密钥，或使用已有的密钥。

    如果您还没有账户，[请在 brightdata.com 上注册](https://www.bright.cn/products/web-scraper/chatgpt?hs_signup=1\&utm_source=docs)。新账户每月可获得 5,000 个免费积分，无需信用卡。请参阅[免费套餐](/cn/general/account/billing-and-pricing/free-tier)。

    <Warning>
      您的 API 密钥仅在创建时显示一次。请复制并安全地存储它。
    </Warning>
  </Step>

  <Step title="发送请求">
    我们将使用**ChatGPT 搜索端点**。最快的方式是使用 Bright Data Python SDK（`pip install brightdata-sdk`），它会替您等待结果。其他选项卡通过同步请求直接调用 API。将 `YOUR_API_KEY` 替换为您的实际密钥：

    <CodeGroup>
      ```python Python SDK theme={null}
      # pip install brightdata-sdk
      from brightdata import SyncBrightDataClient

      # The Scraper API uses no zones, so skip the SDK's zone setup
      with SyncBrightDataClient(token="YOUR_API_KEY", auto_create_zones=False) as client:
          result = client.scrape.chatgpt.prompt("Top hotels in New York")
          print(result.data)
      ```

      ```bash cURL theme={null}
      curl -X POST \
        "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_m7aof0k82r803d5bjm&format=json" \
        -H "Authorization: Bearer YOUR_API_KEY" \
        -H "Content-Type: application/json" \
        -d '[{"url": "https://chatgpt.com/", "prompt": "Top hotels in New York"}]'
      ```

      ```python Python theme={null}
      import requests

      response = requests.post(
          "https://api.brightdata.com/datasets/v3/scrape",
          params={"dataset_id": "gd_m7aof0k82r803d5bjm", "format": "json"},
          headers={
              "Authorization": "Bearer YOUR_API_KEY",
              "Content-Type": "application/json",
          },
          json=[{"url": "https://chatgpt.com/", "prompt": "Top hotels in New York"}],
      )

      data = response.json()
      if response.status_code == 202:
          print(f"Job running. Snapshot ID: {data['snapshot_id']}")
      else:
          print(data)
      ```

      ```javascript Node.js theme={null}
      const response = await fetch(
        "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_m7aof0k82r803d5bjm&format=json",
        {
          method: "POST",
          headers: {
            "Authorization": "Bearer YOUR_API_KEY",
            "Content-Type": "application/json",
          },
          body: JSON.stringify([
            { url: "https://chatgpt.com/", prompt: "Top hotels in New York" }
          ]),
        }
      );

      const data = await response.json();
      if (response.status === 202) {
        console.log(`Job running. Snapshot ID: ${data.snapshot_id}`);
      } else {
        console.log(data);
      }
      ```
    </CodeGroup>

    SDK 会输出 `result.data` 中返回的记录。它最多等待 120 秒获取结果，因此您无需自行处理 `202`。使用 cURL、Python 或 Node.js 时，您应该看到 `200` 状态码和一个 JSON 数组。`202` 表示抓取需要超过 1 分钟，请参阅下方说明。处理时间取决于目标网站状况和爬虫负载。

    <Note>
      同步请求最多等待 1 分钟。如果 Bright Data ChatGPT Scraper API 需要更长时间，响应为 HTTP `202`，返回 `snapshot_id` 而不是搜索结果数据，采集将继续以异步方式进行。请通过[异步工作流](/cn/products/scrapers/scrapers-library/async-requests)获取结果，或使用 [Webhook 投递](/cn/products/scrapers/scrapers-library/data-delivery)接收结果。
    </Note>
  </Step>

  <Step title="查看响应">
    Bright Data ChatGPT Scraper API 返回一个包含结构化搜索数据的 JSON 数组：

    ```json theme={null}
    [
      {
        "url": "https://chatgpt.com/?q=Top%20hotels%20in%20New%20York",
        "prompt": "Top hotels in New York",
        "answer_text": "Map data is currently unavailable Aman New York 4.3 Отель 2 450 $ The Plaza Hotel The Carlyle, A Rosewood Hotel 4.5 Отель 1 359 $ The Mark Hotel 4.5 Отель 2...",
        "model": null,
        "web_search_triggered": true,
        "citations": [
          {
            "url": "https://www.timeout.com/newyork/hotels/best-luxury-hotels-in-nyc?utm_source=chatgpt.com",
            "title": "16 Best Luxury Hotels in New York City For 2026 | World-Class Hotels in NYC",
            "description": "Time Out Worldwide",
            "icon": null
          }
        ],
        "search_sources": [
          {
            "url": "https://www.timeout.com/newyork/hotels/best-luxury-hotels-in-nyc?utm_source=chatgpt.com",
            "title": "16 Best Luxury Hotels in New York City For 2026 | World-Class Hotels in NYC",
            "snippet": null,
            "rank": 1
          }
        ],
        "prompt_sent_at": "2026-09-06T10:22:47.311Z",
        "answer_html": "<html lang=\"en-US\" dir=\"ltr\" data-theme=\"light\" data-contrast=\"default\" data-build=\"prod-4ec31e730ff961987ab0f9a7e9dd6248f66da3b0\" data-close-image-viewer=\"C...",
        "is_map": true
      }
    ]
    ```

    每个结果对象都包含答案文本、带有源 URL 的引用和元数据。请参阅[完整响应模式](/api-reference/scrapers/ai-search-apis/chatgpt-search-by-prompt)。
  </Step>
</Steps>

您已成功使用 Bright Data ChatGPT Scraper API 通过首个提示搜索了 ChatGPT。

## 常见问题

### 我可以在一个请求中发送多个提示吗？

可以。将更多对象添加到输入数组。Bright Data 建议每个同步请求不超过 20 个输入，这是最佳实践，而非硬性限制。对于更大的批次，请使用[异步 `/trigger` 端点](/products/scrapers/scrapers-library/async-requests)。

```json theme={null}
[
  {"url": "https://chatgpt.com/", "prompt": "Top hotels in New York"},
  {"url": "https://chatgpt.com/", "prompt": "Best restaurants in Paris"},
  {"url": "https://chatgpt.com/", "prompt": "Things to do in Tokyo"}
]
```

### 收到 401 或 403 错误？

验证您的 API 密钥是否正确且未过期。从[账户设置](https://www.bright.cn/cp/setting/users)生成新密钥。有关详情，请参阅[身份验证指南](/api-reference/authentication)。

### 请求超时？

同步请求的超时时间为 1 分钟。如果请求超过此限制，API 返回 HTTP `202` 和 `snapshot_id`，并以异步方式完成任务。对于大批次，请使用[异步工作流](/products/scrapers/scrapers-library/async-requests)。

### 响应数据为空或不完整？

验证 `url` 字段是否设置为 `https://chatgpt.com/`，且 `prompt` 字段不为空。提示内容必须为 4,096 个字符或更少。

## 必须直接调用 API 吗？

不必。Bright Data 的 SDK、CLI 和编程代理工具调用的是同一个 Scraper API，您可以选择最适合自己技术栈的方式开始。

| 客户端 | 安装 | 第一次调用 |
| :- | :- | :- |
| **Python 和 Node.js SDK** | `pip install brightdata-sdk` 或 `npm install @brightdata/sdk` | `client.scrape.chatgpt.prompt(prompt="Top hotels in New York", web_search=True)`；详见 [Python SDK](/cn/api-reference/SDK) 和 [JavaScript SDK](/cn/api-reference/SDK-JS) |
| **CLI** | `npm install -g @brightdata/cli`，然后 `bdata login` | 先运行 `bdata pipelines list` 查看所有 pipeline 名称，再运行 `bdata pipelines <pipeline> "<url>" --pretty`；详见 [CLI 命令](/cn/products/cli/commands) |
| **编程代理** | `npx skills add brightdata/skills` 安装技能；[Bright Data MCP](/cn/products/mcp-server/overview) 服务器将爬虫作为工具暴露 | 详见[编程代理快速开始](/cn/quickstart-coding-agent) |

## 后续步骤

<CardGroup cols={3}>
  <Card title="端点" icon="bolt" href="/products/scrapers/chatgpt/send-first-request">
    每个端点一个请求，附实际抓取的响应。
  </Card>

  <Card title="异步批量请求" icon="layer-group" href="/products/scrapers/scrapers-library/async-requests">
    在单个批处理作业中使用数百个提示搜索 ChatGPT。
  </Card>

  <Card title="设置 Webhook" icon="webhook" href="/cn/products/scrapers/scrapers-library/data-delivery">
    在爬取完成时自动接收结果。
  </Card>
</CardGroup>
