> Documentation index: https://docs.scrapier.io/llms.txt
> Auth: header `X-API-Key: <key>` · Base: https://api.scrapier.io/api/v2 · Synchronous; paginate with `cursor` ← `data.next_cursor`.

# Baidu Search Scraper

Structured Baidu data: send `query`. Cursor-paginated, 1 credit per successful call.

`GET|POST https://api.scrapier.io/api/v2/baidu-search/` · 1 credit per successful call · Cursor-paginated

## Overview

Call `GET /api/v2/baidu-search/` with `query`. The results are in `data.organic_results`; send `data.next_cursor` back as `cursor` to get the next page. 3 optional parameters refine the call (see Parameters).

## Request

```bash
curl -G "https://api.scrapier.io/api/v2/baidu-search/" \
  -H "X-API-Key: YOUR_API_KEY" \
  --data-urlencode "query=机器学习" \
  --max-time 210
```

```python
import requests

resp = requests.get(
    "https://api.scrapier.io/api/v2/baidu-search/",
    headers={"X-API-Key": "YOUR_API_KEY"},
    params={"query": "机器学习"},
    timeout=210,
)
body = resp.json()
if not resp.ok:
    raise RuntimeError(body.get("error") or body.get("detail"))

print(body["data"]["organic_results"])
```

POST with a JSON body works too (same parameters; the body is merged over the query string).

## Parameters

| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| `X-API-Key` (header) | string | yes | — | Your API key. |
| `query` | string | yes | e.g. `机器学习` | Search query (single keyword/phrase). Required on the first call. Ignored when `cursor` is supplied — the cursor carries the original query forward. |
| `cursor` | string | no | — | Pagination cursor returned in the previous response's `next_cursor`. Pass it back unchanged to fetch the next page. When `next_cursor` is null, you have reached the last page. |
| `time_period` | string | no | — | Either stf=START,END\|stftype=1 or JSON object with start_date/end_date (camelCase startDate/endDate accepted) |
| `days` | integer | no | `0` | Shorthand: last N days (overrides time_period if > 0) |
| `use_proxy` | boolean | no | `true` | Route the request through Scrapier's residential proxy pool. Default: `true`. Leave as is unless support tells you otherwise. |
| `raw_data` | boolean | no | `false` | When true, the response carries the full raw upstream payload(s) the scraper received (GraphQL / JSON API bodies, HTML, embedded JSON-LD -- exactly as the platform returned them) under `raw_responses`, in place of the formatted items. When false (default) you get the formatted output. Pagination (`cursor` / `next_cursor`) works the same in both modes. |

## Response

HTTP 200. Results are in `data.organic_results`. Sample from the live catalog, arrays trimmed to 3 items.

```json
{
  "success": true,
  "data": {
    "query": "机器学习",
    "page": 1,
    "page_size": 10,
    "organic_results": [
      {
        "title": "什么是机器学习? - 百度百科",
        "link": "https://baike.baidu.com/item/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0",
        "displayed_link": "baike.baidu.com",
        "snippet": "机器学习是人工智能的一个分支,它使计算机能够通过数据学习,而不是通过明确的编程指令...",
        "position": 1,
        "keyword": "机器学习"
      }
    ],
    "answer_box": [],
    "next_cursor": "eyJoIjoiYWJjMTIzZGVmNDU2IiwicG4iOjEwLCJxIjoi5py65Zmo5a2m5LmgIiwidHAiOiIifQ"
  }
}
```

## Response fields

| Field | Type | Example | Description |
|---|---|---|---|
| `query` | string | `机器学习` |  |
| `page` | integer | `1` |  |
| `page_size` | integer | `10` |  |
| `organic_results` | array | `[1 item]` | The results. |
| `answer_box` | array | `[]` |  |
| `next_cursor` | string | `eyJoIjoiYWJjMTIzZGVmNDU2IiwicG4iOjEwLCJxIjoi5…` | Pass back as `cursor` for the next page. `null` on the last page. |
| `organic_results[].title` | string | `什么是机器学习? - 百度百科` |  |
| `organic_results[].link` | string | `https://baike.baidu.com/item/%E6%9C%BA%E5%99%…` |  |
| `organic_results[].displayed_link` | string | `baike.baidu.com` |  |
| `organic_results[].snippet` | string | `机器学习是人工智能的一个分支,它使计算机能够通过数据学习,而不是通过明确的编程指令...` |  |
| `organic_results[].position` | integer | `1` |  |
| `organic_results[].keyword` | string | `机器学习` |  |

## Pagination

Pass `data.next_cursor` back as `cursor` until it is `null`. Required inputs are ignored once a cursor is sent. Each page is one billed call.

```python
import requests

URL = "https://api.scrapier.io/api/v2/baidu-search/"
HEADERS = {"X-API-Key": "YOUR_API_KEY"}
params = {"query": "机器学习"}
items = []

for _ in range(10):  # each page is one billed call
    resp = requests.get(URL, headers=HEADERS, params=params, timeout=210)
    resp.raise_for_status()
    data = resp.json()["data"]
    items.extend(data.get("organic_results") or [])
    if not data.get("next_cursor"):  # None = last page
        break
    params = {"cursor": data["next_cursor"]}
```

## Errors

Failed calls are free. Branch on HTTP status; the message is in `error` (or `detail`). See https://docs.scrapier.io/errors.md

- **400** Bad input. The exact message varies by endpoint. `{"success":false,"error":"…"}`
- **402** Balance below the endpoint's price. `{"error":"Insufficient credits. Buy more to scrape more.","balance":1,"required":2}`
- **403** Invalid or unknown API key. `{"detail":"Authentication service unavailable or invalid API key."}`
- **429** Throttled — wait for Retry-After. `{"detail":"Request was throttled. Expected available in N seconds."}`
- **404** unknown slug · **503** busy (retry after `Retry-After`) · **5xx** upstream failure or timeout (retry with backoff).

## Notes

- Nothing special: send the inputs, read the result.

## Related

- [All Baidu endpoints](https://docs.scrapier.io/api-reference/baidu.md)
