# Baidu Search API

### Parameters <a href="#parameters" id="parameters"></a>

#### **Scrapingdog Parameters**

| Parameter                                                          | Description                                                                                                                                                               |
| ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>api\_key<br></p><p><mark style="color:red;">required</mark></p> | <p>Your personal API key. Available on your dashboard <br><br>Type: <em><strong>String</strong></em></p>                                                                  |
| html                                                               | <p>This will return the full HTML of the Google page. <br><br>Default Value - <strong><code>false</code></strong> <br><br>Type - <strong><code>String</code></strong></p> |

#### Search Query

| Parameter | Description                                                                                                                                                                                                  |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| query     | <p>This parameter specifies the search query and supports all Baidu search operators (e.g., <code>inurl:</code>, <code>site:</code>, <code>intitle:</code>, etc.).<br><br>Type - <strong>String</strong></p> |

#### Localization

| Parameter | Description                                                                                                                                                                                                                        |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ct        | <p><strong>This parameter sets the language restriction for search results. Available options are:</strong></p><p>1 – All languages<br>2 – Simplified Chinese<br>3 – Traditional Chinese<br><br>Type - <strong>String</strong></p> |

#### Pagination

| Parameter | Description                                                                                                                                                                                                                                                                                                     |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| pn        | <p>This parameter sets the result offset, allowing you to skip a specified number of results. It's used for pagination — for example, <code>0</code> (default) returns the first page, <code>10</code> returns the second page, <code>20</code> the third, and so on.<br><br>Type - <strong>String</strong></p> |
| rn        | <p>Specifies the maximum number of results to return, with a limit of 50. For example, setting it to 10 (default) returns 10 results, 30 returns 30 results, and 50 returns 50 results. This parameter is supported only for desktop and tablet searches.<br><br>Type - <strong>String</strong></p>             |

#### Advanced Filters

| Parameter | Description                                                                                                                                                                                                           |                                                                                                                                                                                                                                                                   |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| gpc       | <p>This parameter specifies the time range for the results. For example, <code>stf=1751356433,1751961233                                                                                                              | stftype=1</code> returns results from the past 7 days. The first number (<code>1751356433</code>) is the Unix timestamp for 7 days ago, and the second (<code>1751961233</code>) is the timestamp for the current time.<br><br>Type - <strong>String</strong></p> |
| q5        | <p>Functions similarly to using <code>inurl:</code> or <code>intitle:</code>. For example, use <code>1</code> to search by page title, and <code>2</code> to search by URL.<br><br>Type - <strong>String</strong></p> |                                                                                                                                                                                                                                                                   |
| q6        | <p>Similar to using <code>site:</code>. (e.g., <code>q6=scrapingdog.com</code> to search for results only from the domain <code>scrapingdog.com</code>).<br><br>Type - <strong>String</strong></p>                    |                                                                                                                                                                                                                                                                   |

#### Advanced Baidu Parameters

| Parameter | Description                                                                                                                                                                                                                                   |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| bs        | <p>Specifies the preceding search query.<br><br>Type - <strong>String</strong></p>                                                                                                                                                            |
| oq        | <p>Indicates the original search query when the user arrives via a related search.<br><br>Type - <strong>String</strong></p>                                                                                                                  |
| f         | <p>Specifies the source of the search. For example, <code>8</code> indicates a standard search, <code>3</code> comes from the suggestion list, and <code>1</code> originates from a related search.<br><br>Type - <strong>String</strong></p> |

### API Example

{% tabs %}
{% tab title="cURL" %}

```
curl "https://api.scrapingdog.com/baidu/search/?api_key=5eaa61a6e562fc52fe763tr516e4653&query=football"
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_key = "5eaa61a6e562fc52fe763tr516e4653"
url = "https://api.scrapingdog.com/baidu/search/"

params = {
    "api_key": api_key,
    "query": "football"
}

response = requests.get(url, params=params)

if response.status_code == 200:
    data = response.json()
    print(data)
else:
    print(f"Request failed with status code: {response.status_code}")

```

{% endtab %}

{% tab title="Node JS" %}

```javascript
const axios = require('axios');

const api_key = '5eaa61a6e562fc52fe763tr516e4653';
const url = 'https://api.scrapingdog.com/baidu/search/';

const params = {
  api_key: api_key,
  query: 'football'
};

axios
  .get(url, { params: params })
  .then(function (response) {
    if (response.status === 200) {
      const data = response.data;
      console.log(data)
    } else {
      console.log('Request failed with status code: ' + response.status);
    }
  })
  .catch(function (error) {
    console.error('Error making the request: ' + error.message);
  });

```

{% endtab %}

{% tab title="PHP" %}

```
<?php

// Set the API key and request parameters
$api_key = '5eaa61a6e562fc52fe763tr516e4653';
$query = 'football';

// Set the API endpoint
$url = 'https://api.scrapingdog.com/baidu/search/?api_key=' . $api_key . '&query=' . $query;

// Initialize cURL session
$ch = curl_init($url);

// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute the cURL request
$response = curl_exec($ch);

// Check if the request was successful
if ($response === false) {
    echo 'cURL error: ' . curl_error($ch);
} else {
    // Process the response data as needed
    echo $response;
}

// Close the cURL session
curl_close($ch);

```

{% endtab %}

{% tab title="Ruby" %}

```
require 'net/http'
require 'uri'

# Set the API key and request parameters
api_key = '5eaa61a6e562fc52fe763tr516e4653'
query = 'football'

# Construct the API endpoint URL
url = URI.parse("https://api.scrapingdog.com/baidu/search/?api_key=#{api_key}&query=#{query}")

# Create an HTTP GET request
request = Net::HTTP::Get.new(url)

# Create an HTTP client
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true # Enable SSL (https)

# Send the request and get the response
response = http.request(request)

# Check if the request was successful
if response.is_a?(Net::HTTPSuccess)
  puts response.body # Process the response data as needed
else
  puts "HTTP request failed with code: #{response.code}, message: #{response.message}"
end

```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.IOException;

public class Main {
    public static void main(String[] args) {
        try {
            // Set the API key and request parameters
            String apiKey = "5eaa61a6e562fc52fe763tr516e4653";
            String query = "football";

            // Construct the API endpoint URL
            String apiUrl = "https://api.scrapingdog.com/baidu/search/?api_key=" + apiKey
                    + "&query=" + query

            // Create a URL object from the API URL string
            URL url = new URL(apiUrl);

            // Open a connection to the URL
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            // Set the request method to GET
            connection.setRequestMethod("GET");

            // Get the response code
            int responseCode = connection.getResponseCode();

            if (responseCode == 200) {
                // Read the response from the connection
                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String inputLine;
                StringBuilder response = new StringBuilder();

                while ((inputLine = reader.readLine()) != null) {
                    response.append(inputLine);
                }
                reader.close();

                // Process the response data as needed
                System.out.println(response.toString());
            } else {
                System.out.println("HTTP request failed with response code: " + responseCode);
            }

            // Close the connection
            connection.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

```

{% endtab %}
{% endtabs %}

### API Response

```json
{
    "Baidu_data": [
        {
            "title": "football(英语单词) - 百度百科",
            "link": "http://www.baidu.com/link?url=9o-kb77pRouo5DHWnh7N-mn9QHoh7uR-_Tc4ONuz5ek6BxXntzTRvIWdi0ryh-Y0CvHV1ecEXjNn0HzO1jh9aa",
            "snippet": "football(英语单词) - 百度百科",
            "rank": 1
        },
        {
            "title": "football是什么意思_football的翻译_音标_读音_用法_例句..._爱词霸",
            "link": "http://www.baidu.com/link?url=9o-kb77pRouo5DHWnh7N-jryfci0W6zZfrr5ueTIfBO7yGnWH4kyyfs1Dl7x7xiX",
            "snippet": "football是什么意思_football的翻译_音标_读音_用法_例句..._爱词霸",
            "rank": 2
        },
        {
            "title": "football是什么意思_football的翻译_音标_读音_用法_例句_爱词霸...",
            "link": "http://www.baidu.com/link?url=SRogbezpoEH9ZPxXy_EGptBwN2aOUhraK79IKXbbED97wz86OFwYC6u2ty6BY9U6",
            "snippet": "football是什么意思_football的翻译_音标_读音_用法_例句_爱词霸...",
            "rank": 3
        },
        {
            "title": "football - 搜索 词典",
            "link": "http://www.baidu.com/link?url=0_upk3l-GcmXnluO0nMU21hpBidqcSiR7xwKjPjT8ahh7tsKv5qb42oh6uTEidNN",
            "snippet": "football - 搜索 词典",
            "rank": 4
        },
        {
            "title": "football是什么意思_football怎么读_中文意思_用法_翻译",
            "link": "http://www.baidu.com/link?url=SRogbezpoEH9ZPxXy_EGpxWPuZhdHL5z3oQi9a__POoqAqujoNECBqgoLg396MXt",
            "snippet": "football是什么意思_football怎么读_中文意思_用法_翻译",
            "rank": 5
        },
        {
            "title": "football是什么意思_football的中文翻译_音标_读音_用法_例句...",
            "link": "http://www.baidu.com/link?url=9o-kb77pRouo5DHWnh7N-jkd-EXWIUbdalZLAVr-C4X3sI6iEs2sgMsX99gKOaLVHi4VmpD1ogv_uG7HiPfQbK",
            "snippet": "football是什么意思_football的中文翻译_音标_读音_用法_例句...",
            "rank": 6
        },
        {
            "title": "football是什么意思|football的音标|football的用法 - 英语词典",
            "link": "http://www.baidu.com/link?url=eYfUdpNmr_BQDg6sDceS6WrG5vI5wZzE_J8iv9QoJlKaoN3t9-Mfy5AwEtm-N-tO435aKtvlQmGHStTXK_QvqUWfeY5RgMjIfwh8jgcLFTa",
            "snippet": "football是什么意思|football的音标|football的用法 - 英语词典",
            "rank": 7
        },
        {
            "title": "FOOTBALL中文(简体)翻译:剑桥词典",
            "link": "http://www.baidu.com/link?url=eYfUdpNmr_BQDg6sDceS6Z2aeBOtFmxR5SOmDN4pw1geyA16UbTVBuHgRd-v_3j3Yz-Iyjl0US-pY60cA5AcrjQ0TFjma9YHNilfGKDXz6W72q1tXhlbi5-qw5wl8o8WiWg2kHbL2tH19uNqFvezJesqOSsTi-K3SzWbK2dSoJKnc_z-R0yTpZpx1u0nX4c5",
            "snippet": "FOOTBALL中文(简体)翻译:剑桥词典",
            "rank": 8
        }
    ]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.scrapingdog.com/baidu-scraper-api/baidu-search-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
