> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/api-targets/cn/search-engines/bing/search.md).

# 搜索

提取 Bing Search 结果及其付费广告和自然列表的解析后数据，支持地理位置定位、域名本地化和分页。

该 `bing_search` source 旨在检索 Bing Search 结果页（SERPs）。

{% hint style="info" %}
要抓取 **AI 生成的搜索结果** 来自 Bing，请使用 `render` 参数一起使用时才有用。
{% endhint %}

## 请求示例

在下面的示例中，我们发起请求以检索搜索词的 Bing 搜索结果 `adidas`. 搜索将从第 11 页开始，检索 10 页结果，并以结构化格式返回。

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

```shell
curl 'https://realtime.oxylabs.io/v1/queries' \\
--user 'USERNAME:PASSWORD' \\
-H 'Content-Type: application/json' \\
-d '{
        "source": "bing_search",
        "domain": "com",
        "query": "adidas",
        "start_page": 11,
        "pages": 10,
        "callback_url": "https://your.callback.url",
        "parse": true
    }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from pprint import pprint

# 结构化载荷。
payload = {
    'source': 'bing_search',
    'domain': 'com',
    'query': 'adidas',
    'start_page': 11,
    'pages': 10,
    'callback_url': 'https://your.callback.url',
    'parse': True
}

# 获取响应。
response = requests.request(
    'POST',
    'https://realtime.oxylabs.io/v1/queries',
    auth=('USERNAME', 'PASSWORD'),
    json=payload,
)

# Print prettified response to stdout.
pprint(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const https = require("https");

const username = "USERNAME";
const password = "PASSWORD";
const body = {
    source: "bing_search",
    domain: "com",
    query: "adidas",
    start_page: 11,
    pages: 10,
    callback_url: "https://your.callback.url",
    解析：true,
};

const options = {
    hostname: "realtime.oxylabs.io",
    path: "/v1/queries",
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        Authorization:
            "Basic " + Buffer.from(`${username}:${password}`).toString("base64"),
    },
};

const request = https.request(options, (response) => {
    let data = "";

    response.on("data", (chunk) => {
        data += chunk;
    });

    response.on("end", () => {
        const responseData = JSON.parse(data);
        console.log(JSON.stringify(responseData, null, 2));
    });
});

request.on("error", (error) => {
    console.error("Error:", error);
});

request.write(JSON.stringify(body));
request.end();
```

{% endtab %}

{% tab title="HTTP" %}

```http
https://realtime.oxylabs.io/v1/queries?source=bing_search&domain=com&query=adidas&start_page=11&pages=10&parse=true&access_token=12345abcdep
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$params = array(
    'source' => 'bing_search',
    'domain' => 'com',
    'query' => 'adidas',
    'start_page' => 11,
    'pages' => 10,
    'callback_url' => 'https://your.callback.url',
    'parse' => true
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://realtime.oxylabs.io/v1/queries");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "USERNAME" . ":" . "PASSWORD");

$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
```

{% endtab %}

{% tab title="Golang" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	const Username = "USERNAME"
	const Password = "PASSWORD"

	payload := map[string]interface{}{
		"source":       "bing_search",
		"domain":       "com",
		"query":        "adidas",
		"start_page":   11,
		"pages":        10,
		"callback_url": "https://your.callback.url",
		"parse":        true,
	}

	jsonValue, _ := json.Marshal(payload)

	client := &http.Client{}
	request, _ := http.NewRequest("POST",
		"https://realtime.oxylabs.io/v1/queries",
		bytes.NewBuffer(jsonValue),
	)

	request.SetBasicAuth(Username, Password)
	response, _ := client.Do(request)

	responseText, _ := ioutil.ReadAll(response.Body)
	fmt.Println(string(responseText))
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;

namespace OxyApi
{
    class Program
    {
        static async Task Main()
        {
            const string Username = "USERNAME";
            const string Password = "PASSWORD";

            var parameters = new {
                source = "bing_search",
                domain = "com",
                query = "adidas",
                start_page = 11,
                pages = 10,
                callback_url = "https://your.callback.url",
                parse = true
            };

            var client = new HttpClient();

            Uri baseUri = new Uri("https://realtime.oxylabs.io");
            client.BaseAddress = baseUri;

            var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/v1/queries");
            requestMessage.Content = JsonContent.Create(parameters);

            var authenticationString = $"{Username}:{Password}";
            var base64EncodedAuthenticationString = Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(authenticationString));
            requestMessage.Headers.Add("Authorization", "Basic " + base64EncodedAuthenticationString);

            var response = await client.SendAsync(requestMessage);
            var contents = await response.Content.ReadAsStringAsync();

            Console.WriteLine(contents);
        }
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
package org.example;

import okhttp3.*;
import org.json.JSONObject;
import java.util.concurrent.TimeUnit;

public class Main implements Runnable {
    private static final String AUTHORIZATION_HEADER = "Authorization";
    public static final String USERNAME = "USERNAME";
    public static final String PASSWORD = "PASSWORD";

    public void run() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("source", "bing_search");
        jsonObject.put("domain", "com");
        jsonObject.put("query", "adidas");
        jsonObject.put("start_page", 11);
        jsonObject.put("pages", 10);
        jsonObject.put("callback_url", "https://your.callback.url");
        jsonObject.put("parse", true);

        Authenticator authenticator = (route, response) => {
            String credential = Credentials.basic(USERNAME, PASSWORD);
            return response
                    .request()
                    .newBuilder()
                    .header(AUTHORIZATION_HEADER, credential)
                    .build();
        };

        var client = new OkHttpClient.Builder()
                .authenticator(authenticator)
                .readTimeout(180, TimeUnit.SECONDS)
                .build();

        var mediaType = MediaType.parse("application/json; charset=utf-8");
        var body = RequestBody.create(jsonObject.toString(), mediaType);
        var request = new Request.Builder()
                .url("https://realtime.oxylabs.io/v1/queries")
                .post(body)
                .build();

        try (var response = client.newCall(request).execute()) {
            if (response.body() != null) {
                try (var responseBody = response.body()) {
                    System.out.println(responseBody.string());
                }
            }
        } catch (Exception exception) {
            System.out.println("Error: " + exception.getMessage());
        }

        System.exit(0);
    }

    public static void main(String[] args) {
        new Thread(new Main()).start();
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
    "source": "bing_search",
    "domain": "com",
    "query": "adidas",
    "start_page": 11,
    "pages": 10,
    "callback_url": "https://your.callback.url",
    "parse": true
}
```

{% endtab %}
{% endtabs %}

我们在示例中使用同步 [**Realtime**](/products/cn/web-scraper-api/integration-methods/realtime.md) 集成方法。如果您想使用 [**Proxy Endpoint**](/products/cn/web-scraper-api/integration-methods/proxy-endpoint.md) 或异步 [**Push-Pull**](/products/cn/web-scraper-api/integration-methods/push-pull.md) 集成，请参阅 [**集成方法**](/products/cn/web-scraper-api/integration-methods.md) 部分。

在下面的示例中，我们发送一个请求，以获取搜索词的 AI 生成 Bing 搜索结果 `最佳 SEO 工具`.

```json
{
    "source": "bing_search", 
    "query": "最佳 SEO 工具", 
    "render": "html"
}
```

## 请求参数值

### 通用

Bing 搜索抓取的基本设置和自定义选项。

<table><thead><tr><th width="222">参数</th><th width="350.3333333333333">描述</th><th>默认值</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><strong>source</strong></mark></td><td>设置抓取器。</td><td><code>bing_search</code></td></tr><tr><td><mark style="background-color:green;"><strong>查询</strong></mark></td><td>要搜索的关键词或短语。</td><td>-</td></tr><tr><td><code>render</code></td><td>设置为时启用 JavaScript 渲染 <code>html</code>. <a href="/products/cn/web-scraper-api/features/js-rendering-and-browser-control.md#javascript-rendering"><strong>更多信息</strong></a><strong>.</strong></td><td>-</td></tr><tr><td><code>解析</code></td><td>设置为以下值时返回解析后的数据： <code>true</code>。查看输出 <a href="#output-data-dictionary"><strong>数据字典</strong></a>.</td><td><code>false</code></td></tr><tr><td><code>callback_url</code></td><td>回调端点的 URL。 <a href="/products/cn/web-scraper-api/integration-methods/push-pull.md"><strong>更多信息</strong></a></td><td>-</td></tr><tr><td><code>user_agent_type</code></td><td>设备类型和浏览器。完整列表可在 <a href="/products/cn/web-scraper-api/features/http-context-and-job-management/user-agent-type.md"><strong>此处</strong></a>.</td><td><code>desktop</code></td></tr></tbody></table>

\- 必填参数

### 本地化

将搜索结果适配到特定地理位置、域和语言。

<table><thead><tr><th width="222">参数</th><th width="350.3333333333333">描述</th><th>默认值</th></tr></thead><tbody><tr><td><code>geo_location</code></td><td>指定搜索结果的位置。支持城市、州、国家或坐标格式。 <a href="/products/cn/web-scraper-api/features/localization.md"><strong>阅读更多</strong></a><strong>.</strong></td><td>-</td></tr><tr><td><code>domain</code></td><td>将结果本地化到某个国家。有效值： <code>com</code>, <code>ru</code>, <code>ua</code>, <code>by</code>, <code>kz</code>, <code>tr</code>.</td><td><code>com</code></td></tr><tr><td><code>locale</code></td><td><code>Accept-Language</code> 可更改 Bing 搜索页面 Web 界面语言的请求头值。 <a href="/products/cn/web-scraper-api/features/localization/domain-locale.md#bing"><strong>更多信息</strong></a>.</td><td>-</td></tr></tbody></table>

### 分页

用于管理搜索结果分页和检索的控件。

<table><thead><tr><th width="222">参数</th><th width="350.3333333333333">描述</th><th width="167">默认值</th></tr></thead><tbody><tr><td><code>start_page</code></td><td>起始页码。</td><td><code>1</code></td></tr><tr><td><code>pages</code></td><td>要检索的页数。</td><td><code>1</code></td></tr><tr><td><code>限制</code></td><td>每页要检索的结果数量。</td><td><code>10</code></td></tr></tbody></table>

## 结构化数据

SERP 爬虫 API 能够提取包含 Bing 搜索结果的 HTML 或 JSON 对象，并为结果页的各个元素提供结构化数据。

{% file src="/files/cbfd4e2540b8f2d0015b1d77f735303d6d8e8bd3" %}

## 输出数据字典

#### **HTML 示例**

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXek9v-EPIfkuBe9agDrGzoz2gQspI2bjipHUUGSl2Y7sW1NB1ZBUSTdAlG-VzFcG0m-Anei0qj3E4b4h_N-RgJhrHSaqFDF8WvVIXaJLOodVj_mxmnRtIh9e9ViRaxZrQhhL3Ntd9dARaGg-px-j0xQVYU?key=NG4r24r-hbhCkjE_d7r1ZQ" alt="" width="563"><figcaption></figcaption></figure>

#### JSON 结构

下表列出了我们解析的每个 SERP 功能的详细清单，以及其描述和数据类型。表中还包含一些元数据。

<table><thead><tr><th width="233">键</th><th width="366">描述</th><th>类型</th></tr></thead><tbody><tr><td><code>url</code></td><td>Bing 搜索页面的 URL。</td><td>字符串</td></tr><tr><td><code>page</code></td><td>当前页码。</td><td>整数</td></tr><tr><td><code>results</code></td><td>包含搜索结果的字典。</td><td>对象</td></tr><tr><td><code>付费</code> （可选）</td><td>包含各自详情的赞助结果清单。</td><td>数组</td></tr><tr><td><code>organic</code></td><td>包含各自详情的未付费列表。</td><td>数组</td></tr><tr><td><code>parse_status_code</code></td><td>解析任务的状态码。你可以查看所描述的解析器状态码 <a href="https://github.com/oxylabs/gitbook-public-english/blob/master/scraping-solutions/web-scraper-api/targets/bing/broken-reference/README.md"><strong>此处</strong></a>.</td><td>整数</td></tr><tr><td><code>创建时间</code></td><td>抓取任务创建时的时间戳。</td><td>时间戳</td></tr><tr><td><code>更新时间</code></td><td>抓取任务完成时的时间戳。</td><td>时间戳</td></tr><tr><td><code>状态码</code></td><td>抓取任务的状态码。你可以查看所描述的抓取器状态码 <a href="https://github.com/oxylabs/gitbook-public-english/blob/master/scraping-solutions/web-scraper-api/targets/bing/broken-reference/README.md"><strong>此处</strong></a>.</td><td>整数</td></tr><tr><td><code>任务ID</code></td><td>与该抓取任务关联的任务 ID。</td><td>字符串</td></tr></tbody></table>

{% hint style="info" %}
在以下部分中，当某个结果类型有多个项目可用时，已将解析后的 JSON 代码片段缩短。
{% endhint %}

### 付费

<figure><img src="https://1830353461-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBaJCXoqO1zdFnaMnCKrg%2Fuploads%2Fgit-blob-a26f130fc02d2cbbd7d7e2abdd24bf5a103016a8%2Fbing_search.png?alt=media" alt=""><figcaption></figcaption></figure>

```json
...
  "paid": [
    {
        "pos": 1,
        "url": "https://www.bing.com/aclick?ld=e8TB2-TOVbuwbSri4984NcRjVUCUyQghxnzejHV59xXn6r9lgz7ciPH0EL82ftdUCMBGEyAqiFGOiPXPkAOfdD7Y-Xpb6_pZlMPNZ2x6tTn4WAr8KA0oPNQYW031wP0d8g-pQsdx7BmXEN9ZojHVTY7Jznw7BafmzDSQCtL-MgYN9BRUmeBp74Eo3wYCJfbPIT_cWI2g&u=aHR0cCUzYSUyZiUyZnd3dy5yZW1pc2VzZW5saWduZS5mciUyZmJhc2tldC1uaWtlLWpvcmRhbiUzZnRhcmdldGlkJTNka3dkLTg1MTQ0NzUwMTM5NzExJTI2bWF0Y2h0eXBlJTNkcCUyNmRldmljZSUzZGMlMjZjYW1wYWlnbmlkJTNkNTMxMzY2ODQ3JTI2Y3JlYXRpdmUlM2QlMjZhZGdyb3VwaWQlM2QxMzYyMjk3NDM4ODkzNDg1JTI2ZmVlZGl0ZW1pZCUzZCUyNmxvY19waHlzaWNhbF9tcyUzZDE0MzAyNyUyNmxvY19pbnRlcmVzdF9tcyUzZCUyNm5ldHdvcmslM2RvJTI2ZGV2aWNlbW9kZWwlM2QlMjZwbGFjZW1lbnQlM2QlMjZrZXl3b3JkJTNkJTI0YmFza2V0JTI1MjBuaWtlJTI1MjBqb3JkYW4lMjZ0YXJnZXQlM2QlMjZhZHBvc2l0aW9uJTNkJTI2dHJhY2tpZCUzZGZyX2FsbF9kZWFsc18yX2JpbmclMjZtSWQlM2RIMTQ5MDAzQ1FOJTI2bXNjbGtpZCUzZDc5NjY4ODI4MDQ0ODE2NjVjNTJmZWU0MTc4Yjk1NWJm&rlid=7966882804481665c52fee4178b955bf",
        "desc": "Neue Releases, Retro-Klassiker & zeitlose Ikonen. Entdecke Air Jordan bei Nike. Meistere das Spiel und erlebe Tradition neu mit Air Jordan von Nike.",
        "title": "Offizielle Air Jordan Webseite | Shoppe Nike Jumpman-Produkte",
        "url_shown": "www.nike.com/air/jordan",
        "pos_overall": 11
    },
    {
        "pos": 2,
        "url": "https://www.bing.com/aclick?ld=e8OBM60EyxdN2Qxvp-arD9JzVUCUwier4bXHLFD_dsME5lB1Pg9YnfVggGJSi3ORhgEF-Gwzqx3PiuxHd6fxx0MXN6JKmkwjaGnD2ROEo6W3eTA9fAn8bfi9vpeZ8xEeTyyq8sKhHcKj58HK6h9JnOT7G7zLTYg6MFHaWaGo06uKP4G58bRvFt98DUBKhWj8fd_L867A&u=aHR0cHMlM2ElMmYlMmZ3d3cuYW1hem9uLmNvbSUyZnMlMmYlM2ZpZSUzZFVURjglMjZrZXl3b3JkcyUzZHdvbWVuJTI1MjdzJTJiYWlyJTJiam9yZGFuJTJicmV0cm8lMmIxJTJiZWxldmF0ZSUyYmxvdyUyYmNhc3VhbCUyYnNob2VzJTI2aW5kZXglM2RhcHMlMjZ0YWclM2RtaDBiLTIwJTI2cmVmJTNkcGRfc2xfM2ltOXJscjRkb19iJTI2YWRncnBpZCUzZDEzMzkyMDc1NjMwMTkxMTIlMjZodmFkaWQlM2Q4MzcwMDczNjAyNTQ5NiUyNmh2bmV0dyUzZG8lMjZodnFtdCUzZGIlMjZodmJtdCUzZGJiJTI2aHZkZXYlM2RjJTI2aHZsb2NpbnQlM2QlMjZodmxvY3BoeSUzZDE0MzAyNyUyNmh2dGFyZ2lkJTNka3dkLTgzNzAxNTIzNzAwNjc0JTI2aHlkYWRjciUzZDgwNDJfMTM0Njc2MjQlMjZtc2Nsa2lkJTNkMTg4YzJhMmJhNzg0MWE2MWExY2M0YzQyZGI3NWJhMTU&rlid=188c2a2ba7841a61a1cc4c42db75ba15",
        "desc": "Foot Locker Online 的运动鞋及更多。优质系列和服装！",
        "title": "Jordan - Foot Locker 德国 | Foot Locker 德国",
        "url_shown": "www.footlocker.de",
        "pos_overall": 12
    }
],
...
```

<table><thead><tr><th width="169">键（付费）</th><th width="387">描述</th><th>类型</th></tr></thead><tbody><tr><td><code>pos</code></td><td>广告在付费广告列表中的位置。</td><td>整数</td></tr><tr><td><code>url</code></td><td>付费广告的完整 URL。</td><td>字符串</td></tr><tr><td><code>描述</code></td><td>广告内容的简要描述或摘要。</td><td>字符串</td></tr><tr><td><code>title</code></td><td>广告的主要标题。</td><td>字符串</td></tr><tr><td><code>url_shown</code></td><td>向用户显示的简化 URL。</td><td>字符串</td></tr><tr><td><code>pos_overall</code></td><td>广告在所有搜索结果中的排名，包括付费和自然结果。</td><td>整数</td></tr></tbody></table>

### 自然搜索

<figure><img src="https://1830353461-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBaJCXoqO1zdFnaMnCKrg%2Fuploads%2Fgit-blob-556033fe6c50b5d1cab248330b08f3e39b3b138f%2FScreenshot%202024-06-17%20at%2012.16.42.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

```json
...
"organic": [
    {
        "pos": 1,
        "url": "https://www.bing.com/ck/a?!&&p=dfe8ec2f6aa2c9deJmltdHM9MTcxODU4MjQwMCZpZ3VpZD0wNzdiZTI5My05ZWM4LTZkNWYtMDE0Ni1mNjMyOWZmMzZjMDEmaW5zaWQ9NTIwOA&ptn=3&ver=2&hsh=3&fclid=077be293-9ec8-6d5f-0146-f6329ff36c01&psq=nike+jordan+shoes&u=a1aHR0cHM6Ly93d3cubmlrZS5jb20vcGgvdy9qb3JkYW4tc2hvZXMtMzdlZWZ6eTdvaz9tc29ja2lkPTA3N2JlMjkzOWVjODZkNWYwMTQ2ZjYzMjlmZjM2YzAx&ntb=1",
        "desc": "WEB在 Nike.com 查找 Jordan 鞋。部分订单可享免费送货和退货。",
        "title": "Jordan Shoes. Nike PH",
        "url_shown": "https://www.nike.com/ph/w/jordan-shoes-37eefzy7ok",
        "pos_overall": 1
    },
...
```

<table><thead><tr><th width="209">键（organic）</th><th width="384">描述</th><th>类型</th></tr></thead><tbody><tr><td><code>pos</code></td><td>自然结果在自然搜索结果列表中的排名。</td><td>整数</td></tr><tr><td><code>url</code></td><td>自然搜索结果的完整 URL。</td><td>字符串</td></tr><tr><td><code>描述</code></td><td>自然搜索结果内容的简要描述或摘要。</td><td>字符串</td></tr><tr><td><code>title</code></td><td>自然搜索结果的主要标题。</td><td>字符串</td></tr><tr><td><code>url_shown</code></td><td>向用户显示的简化 URL。</td><td>字符串</td></tr><tr><td><code>pos_overall</code></td><td>自然结果在所有搜索结果中的排名，包括付费和自然结果。</td><td>整数</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://developers.oxylabs.io/api-targets/cn/search-engines/bing/search.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
