# 构建请求

阅读关于如何开始并使用以下内容发出请求的详细指南： [**Web Scraper API**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api) 针对不同网站。

## 搜索引擎

### 入门指南

选择您要抓取的搜索引擎： [**Google**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/targets/google), [**Bing**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/targets/bing), [**其他搜索引擎**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/targets/generic-target).

### 请求示例

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

```shell
curl 'https://realtime.oxylabs.io/v1/queries' \
--user 'USERNAME:PASSWORD' \
-H 'Content-Type: application/json' \
-d '{
        "source": "google_search",
        "query": "adidas"
    }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from pprint import pprint

# 构建负载。
payload = {
    'source': 'google_search',
    'query': 'adidas',
}

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

# 将格式化后的响应打印到 stdout。
pprint(response.json())
```

{% endtab %}

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

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

const username = "USERNAME";
const password = "PASSWORD";
const body = {
    source: "google_search",
    query: "adidas",
};

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="PHP" %}

```php
<?php

$params = array(
    'source' => 'google_search',
    'query' => 'adidas',
);

$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="C#" %}

```csharp
using System;
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 = "google_search",
                query = "adidas",
            };

            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.Encoding.ASCII.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="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": "google_search",
		"query":  "adidas",
	}

	jsonValue, _ := json.Marshal(payload)

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

	request.SetBasicAuth(Username, Password)
	request.Header.Set("Content-Type", "application/json")
	response, _ := client.Do(request)

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

{% endtab %}

{% tab title="HTTP" %}

```http
https://realtime.oxylabs.io/v1/queries?source=google_search&query=adidas&access_token=12345abcde
```

{% 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", "google_search");
        jsonObject.put("query", "adidas");

        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": "google_search",
    "query": "adidas"
}
```

{% endtab %}
{% endtabs %}

我们在示例中使用同步的 [**Realtime**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/realtime) 集成方法。如果您想使用 [**Proxy Endpoint**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/proxy-endpoint) 或异步的 [**Push-Pull**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/push-pull) 集成，请参阅 [**集成方法**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods) 部分。

### 构建请求

1. 选择您的集成方式：同步（[**Realtime**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/realtime), [**Proxy Endpoint**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/proxy-endpoint)）或异步（[**Push-Pull**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/push-pull)).
2. 在构建请求时，请包含以下要素：

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

1. **端点：**

```
POST https://realtime.oxylabs.io/v1/queries
```

2. **用户名和密码** ([**HTTP 认证**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication))**.** 在试用注册或购买产品时创建 API 用户凭据 [**试用注册或产品购买期间**](https://dashboard.oxylabs.io/en/registration?productToBuy=SCRAPI_SERP)**.**

```
USERNAME:PASSWORD
```

{% hint style="warning" %}
如果您需要为您的帐户创建多个 API 用户，请联系我们的 [**客户支持**](mailto:support@oxylabs.io) 或通过我们的 24/7 在线聊天支持联系。
{% endhint %}

3. **Content-type**提交作业时，请始终添加此头：

```
Content-Type: application/json
```

4. **负载：**
   1. `source` - 此参数设置将用于处理您请求的抓取器。
   2. `URL` 或 `query` - 提供您想要抓取的页面类型的 `URL` 或 `query` 有关何时使用每个参数的详细指南，请参阅下表及相应的目标子页面。
   3. [**附加参数**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features)：可选地，您可以包含附加参数，例如 `geo_location`, `user_agent_type`, `parse`, `render` 等，以自定义您的抓取请求。

```json
{
    "source": "google_search",
    "query": "adidas",
    "geo_location": "California,United States",
    "parse": true
}
```

{% endtab %}

{% tab title="Proxy Endpoint" %}

1. **端点：**

```
GET realtime.oxylabs.io:60000
```

2. **忽略证书。** 在 `cURL`中，使用 `-k` 或 `--insecure`.
3. **用户名和密码** ([**HTTP 认证**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication))**.** 在试用注册或购买产品时创建 API 用户凭据 [**试用注册或产品购买期间**](https://dashboard.oxylabs.io/en/registration?productToBuy=SCRAPI_SERP)**.**

```
USERNAME:PASSWORD
```

{% hint style="warning" %}
如果您需要为您的帐户创建多个 API 用户，请联系我们的 [**客户支持**](mailto:support@oxylabs.io) 或通过我们的 24/7 在线聊天支持联系。
{% endhint %}

4. **负载：**
   1. `URL` - 提供您想要抓取的页面类型的 `URL` 用于您想要抓取的页面。
   2. [**附加参数**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features)：可选地，您可以包含附加参数，例如 `geo_location`, `user_agent_type`, `parse`，并将它们作为头发送。

```bash
curl -k -x realtime.oxylabs.io:60000 \
-U "USERNAME:PASSWORD" \
'https://www.google.com/search?q=adidas' \
-H "x-oxylabs-geo-location: California,United States" \
-H "x-oxylabs-parse: 1"
```

{% endtab %}

{% tab title="Push-Pull" %}

1. **端点：**

```
POST https://data.oxylabs.io/v1/queries
```

2. **用户名和密码** ([**HTTP 认证**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication))**.** 在试用注册或购买产品时创建 API 用户凭据 [**试用注册或产品购买期间**](https://dashboard.oxylabs.io/en/registration?productToBuy=SCRAPI_SERP)**.**

```
USERNAME:PASSWORD
```

{% hint style="warning" %}
如果您需要为您的帐户创建多个 API 用户，请联系我们的 [**客户支持**](mailto:support@oxylabs.io) 或通过我们的 24/7 在线聊天支持联系。
{% endhint %}

3. **Content-type**提交作业时，请始终添加此头：

```
Content-Type: application/json
```

4. **负载：**
   1. `source` - 此参数设置将用于处理您请求的抓取器。
   2. `URL` 或 `query` - 提供您想要抓取的页面类型的 `URL` 或 `query` 有关何时使用每个参数的详细指南，请参阅下表及相应的目标子页面。
   3. [**附加参数**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features)：可选地，您可以包含附加参数，例如 `geo_location`, `user_agent_type`, `parse`等，以自定义您的抓取请求。

```json
{
    "source": "google_search",
    "query": "adidas",
    "geo_location": "California,United States",
    "parse": true
}
```

5. 提交请求后，您将立即收到一个 JSON 响应，其中包含所有作业详细信息，包括作业参数、作业 ID 以及用于下载作业结果的 URL：

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results
```

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results?type=raw
```

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results?type=parsed
```

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results?type=png
```

{% endtab %}
{% endtabs %}

<table><thead><tr><th width="217">目标</th><th width="246">来源（抓取 URL）</th><th>来源（使用查询）</th></tr></thead><tbody><tr><td><a href="../zhua-qu-jie-jue-fang-an/web-scraper-api/targets/google"><strong>Google</strong></a></td><td><code>google</code></td><td><p><code>google_search</code>,</p><p><code>google_ads</code>,</p><p><code>google_lens</code>,</p><p><code>google_maps</code>,</p><p><code>google_travel_hotels</code>,</p><p><code>google_trends_explore</code></p></td></tr><tr><td><a href="../zhua-qu-jie-jue-fang-an/web-scraper-api/targets/bing"><strong>Bing</strong></a></td><td><code>bing</code></td><td><code>bing_search</code></td></tr><tr><td><a href="../zhua-qu-jie-jue-fang-an/web-scraper-api/targets/generic-target"><strong>其他搜索引擎</strong></a></td><td><code>universal</code></td><td>使用 <code>query</code> 参数不受支持</td></tr></tbody></table>

## 市场

### 入门指南

选择您要抓取的在线市场： [**Amazon**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/targets/amazon)**,** [**Google Shopping**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/targets/google)**,** [**Walmart**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/targets/walmart)**,** [**Best Buy**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/targets/north-american-e-commerce/bestbuy)**,** [**Etsy**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/targets/etsy)**,** [**目标**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/targets/north-american-e-commerce/target)**,** [**其他网站**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/targets/generic-target)**.**

### 请求示例

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

```bash
curl 'https://realtime.oxylabs.io/v1/queries' \
--user "USERNAME:PASSWORD" \
-H "Content-Type: application/json" \
-d '{
        "source": "amazon_product",
        "query": "B07FZ8S74R",
        "geo_location": "90210",
        "parse": true
    }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from pprint import pprint

# 构建负载。
payload = {
    'source': 'amazon_product',
    'query': 'B07FZ8S74R',
    'geo_location': '90210',
    'parse': True
}

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

# 将格式化后的响应打印到 stdout。
pprint(response.json())
```

{% endtab %}

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

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

const username = "USERNAME";
const password = "PASSWORD";
const body = {
    source: "amazon_product",
    query: "B07FZ8S74R",
    geo_location: "90210",
    parse: 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="PHP" %}

```php
<?php

$params = array(
    'source' => 'amazon_product',
    'query' => 'B07FZ8S74R',
    'geo_location' => '90210',
    '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="C#" %}

```csharp
using System;
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 = "amazon_product",
                query = "B07FZ8S74R",
                geo_location = "90210",
                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.Encoding.ASCII.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="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":       "amazon_product",
		"query":        "B07FZ8S74R",
		"geo_location": "90210",
		"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)
	request.Header.Set("Content-Type", "application/json")
	response, _ := client.Do(request)

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

{% endtab %}

{% tab title="HTTP" %}

```http
https://realtime.oxylabs.io/v1/queries?source=amazon_product&query=B07FZ8S74R&geo_location=90210&parse=true&access_token=12345abcde
```

{% 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", "amazon_product");
        jsonObject.put("query", "B07FZ8S74R");
        jsonObject.put("geo_location", "90210");
        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": "amazon_product",
    "query": "B07FZ8S74R",
    "geo_location": "90210",
    "parse": true
}
```

{% endtab %}
{% endtabs %}

我们在示例中使用同步的 [**Realtime**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/realtime) 集成方法。如果您想使用 [**Proxy Endpoint**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/proxy-endpoint) 或异步的 [**Push-Pull**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/push-pull) 集成，请参阅 [**集成方法**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods) 部分。

### 构建请求

1. 选择您的集成方式：同步（[**Realtime**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/realtime), [**Proxy Endpoint**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/proxy-endpoint)）或异步（[**Push-Pull**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/push-pull)).
2. 在构建请求时，请包含以下要素：

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

1. **端点：**

```
POST https://realtime.oxylabs.io/v1/queries
```

2. **用户名和密码** ([**HTTP 认证**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication))**.** 在试用注册或购买产品时创建 API 用户凭据 [**试用注册或产品购买期间**](https://dashboard.oxylabs.io/en/registration?productToBuy=SCRAPI_SERP)**.**

```
USERNAME:PASSWORD
```

{% hint style="warning" %}
如果您需要为您的帐户创建多个 API 用户，请联系我们的 [**客户支持**](mailto:support@oxylabs.io) 或通过我们的 24/7 在线聊天支持联系。
{% endhint %}

3. **Content-type**提交作业时，请始终添加此头：

```
Content-Type: application/json
```

4. **负载：**
   1. `source` - 此参数设置将用于处理您请求的抓取器。
   2. `URL` 或 `query` - 提供您想要抓取的页面类型的 `URL` 或 `query` 有关何时使用每个参数的详细指南，请参阅下表及相应的目标子页面。
   3. [**附加参数**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features)：可选地，您可以包含附加参数，例如 `geo_location`, `user_agent_type`, `parse`, `render` 等，以自定义您的抓取请求。

```json
{
    "source": "amazon_product",
    "query": "B07FZ8S74R",
    "geo_location": "90210",
    "parse": true
}
```

{% endtab %}

{% tab title="Proxy Endpoint" %}

1. **端点：**

```
GET realtime.oxylabs.io:60000
```

2. **忽略证书。** 在 `cURL`中，使用 `-k` 或 `--insecure`.
3. **用户名和密码** ([**HTTP 认证**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication))**.** 在试用注册或购买产品时创建 API 用户凭据 [**试用注册或产品购买期间**](https://dashboard.oxylabs.io/en/registration?productToBuy=SCRAPI_SERP)**.**

```
USERNAME:PASSWORD
```

{% hint style="warning" %}
如果您需要为您的帐户创建多个 API 用户，请联系我们的 [**客户支持**](mailto:support@oxylabs.io) 或通过我们的 24/7 在线聊天支持联系。
{% endhint %}

4. **负载：**
   1. `URL` - 提供您想要抓取的页面类型的 `URL` 用于您想要抓取的页面。
   2. [**附加参数**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features)：可选地，您可以包含附加参数，例如 `geo_location`, `user_agent_type`, `parse`，并将它们作为头发送。

```bash
curl -k -x realtime.oxylabs.io:60000 \
-U "USERNAME:PASSWORD" \
'https://www.amazon.com/dp/b07fz8s74r' \
-H "x-oxylabs-geo-location: 90210" \
-H "x-oxylabs-parse: 1"
```

{% endtab %}

{% tab title="Push-Pull" %}

1. **端点：**

```
POST https://data.oxylabs.io/v1/queries
```

2. **用户名和密码** ([**HTTP 认证**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication))**.** 在试用注册或购买产品时创建 API 用户凭据 [**试用注册或产品购买期间**](https://dashboard.oxylabs.io/en/registration?productToBuy=SCRAPI_SERP)**.**

```
USERNAME:PASSWORD
```

{% hint style="warning" %}
如果您需要为您的帐户创建多个 API 用户，请联系我们的 [**客户支持**](mailto:support@oxylabs.io) 或通过我们的 24/7 在线聊天支持联系。
{% endhint %}

3. **Content-type**提交作业时，请始终添加此头：

```
Content-Type: application/json
```

4. **负载：**
   1. `source` - 此参数设置将用于处理您请求的抓取器。
   2. `URL` 或 `query` - 提供您想要抓取的页面类型的 `URL` 或 `query` 有关何时使用每个参数的详细指南，请参阅下表及相应的目标子页面。
   3. [**附加参数**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features)：可选地，您可以包含附加参数，例如 `geo_location`, `user_agent_type`, `parse`等，以自定义您的抓取请求。

```json
{
    "source": "amazon_product",
    "query": "B07FZ8S74R",
    "geo_location": "90210",
    "parse": true
}
```

5. 提交请求后，您将立即收到一个 JSON 响应，其中包含所有作业详细信息，包括作业参数、作业 ID 以及用于下载作业结果的 URL：

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results
```

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results?type=raw
```

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results?type=parsed
```

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results?type=pn
```

{% endtab %}
{% endtabs %}

<table><thead><tr><th width="217">目标</th><th width="246">来源（抓取 URL）</th><th>来源（使用查询）</th></tr></thead><tbody><tr><td><a href="../zhua-qu-jie-jue-fang-an/web-scraper-api/targets/amazon"><strong>Amazon</strong></a></td><td><code>amazon</code></td><td><p><code>amazon_product,</code></p><p><code>amazon_search</code>,</p><p><code>amazon_pricing</code>,</p><p><code>amazon_sellers,</code></p><p><code>amazon_bestsellers,</code></p><p><code>amazon_questions</code></p></td></tr><tr><td><a href="../zhua-qu-jie-jue-fang-an/web-scraper-api/targets/google"><strong>Google Shopping</strong></a></td><td><code>google</code></td><td><p><code>google_shopping_product</code>,</p><p><code>google_shopping_search</code>,</p><p><code>google_shopping_pricing</code></p></td></tr><tr><td><a href="../zhua-qu-jie-jue-fang-an/web-scraper-api/targets/walmart"><strong>Walmart</strong></a><br><a href="../zhua-qu-jie-jue-fang-an/web-scraper-api/targets/north-american-e-commerce/bestbuy"><strong>Best Buy</strong></a><br><a href="../zhua-qu-jie-jue-fang-an/web-scraper-api/targets/etsy"><strong>Etsy</strong></a><br><a href="../zhua-qu-jie-jue-fang-an/web-scraper-api/targets/north-american-e-commerce/target"><strong>目标</strong></a><br><a href="../zhua-qu-jie-jue-fang-an/web-scraper-api/targets/generic-target"><strong>其他网站</strong></a></td><td><code>universal</code></td><td>使用 <code>query</code> 参数不受支持</td></tr></tbody></table>

## 其他网站

### 入门指南

使用我们的 `universal` source 抓取任何 URL。您也可以添加 [**附加参数**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features).&#x20;

### 请求示例

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

```shell
curl 'https://realtime.oxylabs.io/v1/queries' \
--user 'USERNAME:PASSWORD' \
-H 'Content-Type: application/json' \
-d '{
        "source": "universal",
        "url": "https://sandbox.oxylabs.io/"
    }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from pprint import pprint


# 构建负载。
payload = {
    'source': 'universal',
    'url': 'https://sandbox.oxylabs.io/',
    # 'render': 'html', # 如果页面类型需要
}

# 获取响应。
response = requests.request(
    'POST',
    'https://realtime.oxylabs.io/v1/queries',
    auth=('USERNAME', 'PASSWORD'), # 您的凭据填写在此处
    json=payload,
)

# 这将返回带有结果的 JSON 响应，而不是作业状态和结果 URL。
# 整个响应将包含结果的 JSON。
pprint(response.json())
```

{% endtab %}

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

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

const username = "USERNAME";
const password = "PASSWORD";
const body = {
    source: "universal",
    url: "https://sandbox.oxylabs.io/",
    // 'render': 'html' // 如果页面类型需要
};

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
# 您提交的整个字符串必须进行 URL 编码。

https://realtime.oxylabs.io/v1/queries?source=universal&url=https%3A%2F%2Fsandbox.oxylabs.io%2F&access_token=12345abcde
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$params = array(
    'source' => 'universal',
    'url' => 'https://sandbox.oxylabs.io/',
    // 'render' => 'html' // 如果页面类型需要
);

$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": "universal",
		"url":    "https://sandbox.oxylabs.io/",
		// "render": "html" // 如果页面类型需要
	}

	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 = "universal",
                url = "https://sandbox.oxylabs.io/",
                // render = "html", // 如果页面类型需要
            };

            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", "universal");
        jsonObject.put("url", "https://sandbox.oxylabs.io/");

        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": "universal", 
    "url": "https://sandbox.oxylabs.io/"
}
```

{% endtab %}
{% endtabs %}

我们在示例中使用同步的 [**Realtime**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/realtime) 集成方法。如果您想使用 [**Proxy Endpoint**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/proxy-endpoint) 或异步的 [**Push-Pull**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/push-pull) 集成，请参阅 [**集成方法**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods) 部分。

### 构建请求

1. 选择您的集成方式：同步（[**Realtime**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/realtime), [**Proxy Endpoint**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/proxy-endpoint)）或异步（[**Push-Pull**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/integration-methods/push-pull)).
2. 在构建请求时，请包含以下要素：

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

1. **端点：**

```
POST https://realtime.oxylabs.io/v1/queries
```

2. **用户名和密码** ([**HTTP 认证**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication))**.** 在试用注册或购买产品时创建 API 用户凭据 [**试用注册或产品购买期间**](https://dashboard.oxylabs.io/en/registration?productToBuy=SCRAPI_SERP)**.**

```
USERNAME:PASSWORD
```

{% hint style="warning" %}
如果您需要为您的帐户创建多个 API 用户，请联系我们的 [**客户支持**](mailto:support@oxylabs.io) 或通过我们的 24/7 在线聊天支持联系。
{% endhint %}

3. **Content-type**提交作业时，请始终添加此头：

```
Content-Type: application/json
```

4. **负载**.

   1. `source` - 此参数设置将用于处理您请求的抓取器。
   2. `URL` - 提供您想要抓取的页面类型的 `URL` 您要抓取的目标的示例，例如：
      1. **房地产**：Idealista、Redfin、Zillow、Zoopla
      2. **旅游**：Airbnb、Agoda、Booking、TripAdvisor
      3. **汽车**：Crunchbase、ZoomInfo、AngelList、Product Hunt
      4. **公司数据**：Netflix、SoundCloud、YouTube、IMDb
      5. **娱乐**：AutoEurope、Autotrader、RockAuto、Halfords
      6. **任何其他**.
   3. [**附加参数**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features)：可选地，您可以包含附加参数，例如 `geo_location`, `user_agent_type`等，以自定义您的抓取请求。

   <pre class="language-json" data-overflow="wrap"><code class="lang-json">{
       "source": "universal",
       "url": "https://www.zillow.com/homedetails/10066-Cielo-Dr-Beverly-Hills-CA-90210/243990393_zpid/"
   }
   </code></pre>

{% endtab %}

{% tab title="Proxy Endpoint" %}

1. **端点：**

```
GET realtime.oxylabs.io:60000
```

2. **忽略证书。** 在 `cURL`中，使用 `-k` 或 `--insecure`.
3. **用户名和密码** ([**HTTP 认证**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication))**.** 在试用注册或购买产品时创建 API 用户凭据 [**试用注册或产品购买期间**](https://dashboard.oxylabs.io/en/registration?productToBuy=SCRAPI_SERP)**.**

```
USERNAME:PASSWORD
```

{% hint style="warning" %}
如果您需要为您的帐户创建多个 API 用户，请联系我们的 [**客户支持**](mailto:support@oxylabs.io) 或通过我们的 24/7 在线聊天支持联系。
{% endhint %}

4. **负载：**
   1. `URL` - 提供您想要抓取的页面类型的 `URL` 您想要抓取的页面，例如：
      1. **房地产**：Idealista、Redfin、Zillow、Zoopla
      2. **旅游**：Airbnb、Agoda、Booking、TripAdvisor
      3. **汽车**：Crunchbase、ZoomInfo、AngelList、Product Hunt
      4. **公司数据**：Netflix、SoundCloud、YouTube、IMDb
      5. **娱乐**：AutoEurope、Autotrader、RockAuto、Halfords
      6. **任何其他**.
   2. [**附加参数**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features)：可选地，您可以包含附加参数，例如 `geo_location`, `user_agent_type`，并将它们作为头发送。

{% code overflow="wrap" %}

```bash
curl -k -x realtime.oxylabs.io:60000 \
-U "USERNAME:PASSWORD" \
'https://www.zillow.com/homedetails/10066-Cielo-Dr-Beverly-Hills-CA-90210/243990393_zpid/' 
```

{% endcode %}
{% endtab %}

{% tab title="Push-Pull" %}

1. **端点：**

```
POST https://data.oxylabs.io/v1/queries
```

2. **用户名和密码** ([**HTTP 认证**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication))**.** 在试用注册或购买产品时创建 API 用户凭据 [**试用注册或产品购买期间**](https://dashboard.oxylabs.io/en/registration?productToBuy=SCRAPI_SERP)**.**

```
USERNAME:PASSWORD
```

{% hint style="warning" %}
如果您需要为您的帐户创建多个 API 用户，请联系我们的 [**客户支持**](mailto:support@oxylabs.io) 或通过我们的 24/7 在线聊天支持联系。
{% endhint %}

3. **Content-type**提交作业时，请始终添加此头：

```
Content-Type: application/json
```

4. **负载**.

   1. `source` - 此参数设置将用于处理您请求的抓取器。
   2. `URL` - 提供您想要抓取的页面类型的 `URL` 您要抓取的目标的示例，例如：
      1. **房地产**：Idealista、Redfin、Zillow、Zoopla
      2. **旅游**：Airbnb、Agoda、Booking、TripAdvisor
      3. **汽车**：Crunchbase、ZoomInfo、AngelList、Product Hunt
      4. **公司数据**：Netflix、SoundCloud、YouTube、IMDb
      5. **娱乐**：AutoEurope、Autotrader、RockAuto、Halfords
      6. **任何其他**.
   3. [**附加参数**](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features)：可选地，您可以包含附加参数，例如 `geo_location`, `user_agent_type`等，以自定义您的抓取请求。

   <pre class="language-json" data-overflow="wrap"><code class="lang-json">{
       "source": "universal",
       "url": "https://www.zillow.com/homedetails/10066-Cielo-Dr-Beverly-Hills-CA-90210/243990393_zpid/"
   }
   </code></pre>
5. 提交请求后，您将立即收到一个 JSON 响应，其中包含所有作业详细信息，包括作业参数、作业 ID 以及用于下载作业结果的 URL：

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results
```

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results?type=raw
```

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results?type=parsed
```

```
GET https://data.oxylabs.io/v1/queries/{job_id}/results?type=pn
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
如果您在发出首次请求时需要任何帮助，请随时通过 24/7 在线聊天与我们联系。
{% endhint %}

{% hint style="info" %}
*本文中的所有信息均按“原样”提供，仅供参考。对于您使用本页所含任何信息所产生的后果，我们不作任何陈述并否认一切责任。在进行任何形式的抓取活动之前，您应咨询法律顾问并仔细阅读相关网站的服务条款或获得抓取许可。*
{% endhint %}


---

# 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://developers.oxylabs.io/documentation/cn/wang-ye-pa-chong-api-zhi-nan/forming-requests.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.
