# 购物商品

该 `google_shopping_product` source 使用一个从 Google Shopping 获取的商品 token 来检索详细的商品信息（标题、描述、价格、卖家、相关商品、评论等） **商品 token** 从以下来源获取： `google_shopping_search` [source](/api-targets/cn/sou-suo-yin-qing/google/shopping/shopping-search.md).

## **请求样本**

在下面的代码示例中，我们使用有效的 token 发起请求，以检索 Google Shopping 商品的商品页面。

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

```shell
curl 'https://realtime.oxylabs.io/v1/queries' \\
--user 'USERNAME:PASSWORD' \\
-H 'Content-Type: application/json' \\
-d '{
       "source": "google_shopping_product",
       "query": "<PRODUCT_TOKEN>",
       "render": "html",
       "parse": true
    }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from pprint import pprint


# 结构化负载。
payload = {
    "source": "google_shopping_product",
    "query": "[product_token_string]",
    "render": "html",
    "parse": True
}

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

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

{% endtab %}

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

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

const username = "USERNAME";
const password = "PASSWORD";
const body = {
    source: "google_shopping_product",
    query: "[product_token_string]",
    render: "html",
    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);
});

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

{% endtab %}

{% tab title="HTTP" %}

```http
https://realtime.oxylabs.io/v1/queries?source=google_shopping_product&query=[product_token_string]&parse=true&access_token=12345abcde
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$params = array(
    'source' => 'google_shopping_product',
    'query' => '[product_token_string]',
    'render' => 'html',
    '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 '错误:' . 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": "google_shopping_product",
		"query": "[product_token_string]",
		"render": "html",
		"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 = "google_shopping_product",
                query = "[product_token_string]",
                render = "html",
                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", "google_shopping_product");
        jsonObject.put("query", "[product_token_string]");
        jsonObject.put("render", "html");
        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("错误： " + exception.getMessage());
        }

        System.exit(0);
    }

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

{% endtab %}

{% tab title="JSON" %}

```json
{
    "source": "google_shopping_product",
    "query": "[product_token_string]",
    "render": "html",
    "parse": true
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**重要：** 该 `query` 参数必须包含一个通过以下方式生成的有效 token `google_shopping_search` [source](/api-targets/cn/sou-suo-yin-qing/google/shopping/shopping-search.md).
{% endhint %}

我们在示例中使用同步 [**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) 部分。

## 请求参数值

### 通用

用于抓取 Google Shopping 商品页面的基础设置和自定义选项。

<table><thead><tr><th width="222">参数</th><th width="330.3333333333333">描述</th><th>默认值</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><strong><code>source</code></strong></mark></td><td>设置爬虫。</td><td><code>google_shopping_product</code></td></tr><tr><td><mark style="color:默认;background-color:green;"><strong><code>query</code></strong></mark></td><td>来自以下来源的商品 token <code>google_shopping_search</code></td><td>-</td></tr><tr><td><code>render</code></td><td>设置为时启用 JavaScript 渲染 <code>html</code>. <strong>必需</strong> 以接收来自“更多商店”部分的额外价格结果。 <a href="/spaces/ZwEHB9k4MH4pDy80n9mF/pages/9d7133837001de31de5dfd0796cfbc6fdd7c78c8#javascript-rendering"><strong>更多信息</strong></a><strong>.</strong></td><td>-</td></tr><tr><td><code>parse</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="/spaces/ZwEHB9k4MH4pDy80n9mF/pages/f93fe40aed5366f8033cd2ebfae30e61c16a4f51"><strong>更多信息</strong></a></td><td>-</td></tr><tr><td><code>user_agent_type</code></td><td>设备类型和浏览器。完整列表可在 <a href="/spaces/ZwEHB9k4MH4pDy80n9mF/pages/3e6a8ee6a2915a55b276cc31a20735fe1e0e4ed1"><strong>这里</strong></a>.</td><td><code>desktop</code></td></tr></tbody></table>

&#x20;   \- 必填参数

### 本地化

将结果调整为特定的地理位置、域名和语言。

<table><thead><tr><th width="218">参数</th><th width="336.3333333333333">描述</th><th>默认值</th></tr></thead><tbody><tr><td><code>geo_location</code></td><td>结果应适配的地理位置。正确使用此参数对于获取正确数据极其重要。有关更多信息，请阅读我们建议的 <code>geo_location</code> 参数结构 <a href="/pages/2433a984e096906cd77f23c1f269543f60aebf61#google"><strong>这里</strong></a><strong>.</strong></td><td>-</td></tr><tr><td><code>locale</code></td><td><code>Accept-Language</code> 用于界面语言更改的 header 值。 <a href="/pages/6622d022f22939190b3dd6a80812e072ab49b8f4#locale-1"><strong>更多信息</strong></a>.</td><td>-</td></tr></tbody></table>

{% hint style="warning" %}
**注意：** 请确保以下内容的本地化参数 `google_shopping_product` 和 `google_shopping_search` 来源保持一致（如果未定义则为 none）。来源之间的区域不匹配可能会导致数据不完整或不准确。
{% endhint %}

## 结构化数据

下面你可以找到一个 **结构化输出示例** 用于 `google_shopping_product`.

{% file src="/files/46a86d9cff57c37578c228a0762c9b08a1824cb5" %}

## 输出数据字典

**HTML 示例**

<figure><img src="/files/3316be995dce2e2e0a2ca3fc6e3c3aad98ba2994" alt=""><figcaption></figcaption></figure>

#### JSON 结构

下表详细列出了我们解析的每个商品页面元素，以及其描述和数据类型。该表还包含一些元数据。

<table><thead><tr><th width="247.11328125">Amazon Best Sellers 页面的网址。</th><th width="384">描述</th><th>类型</th></tr></thead><tbody><tr><td><code>url</code></td><td>Google Shopping 商品页面的 URL。</td><td>字符串</td></tr><tr><td><code>title</code> （可选） </td><td>商品列表的标题。</td><td>字符串</td></tr><tr><td><code>description</code></td><td>商品的详细描述。</td><td>字符串</td></tr><tr><td><code>images</code></td><td>包含商品图片的对象。</td><td>对象</td></tr><tr><td><code>images.full_size</code></td><td>商品完整尺寸图片 URL 数组。</td><td>数组</td></tr><tr><td><code>images.thumbnails</code></td><td>商品缩略图 URL 数组。</td><td>数组</td></tr><tr><td><code>pricing</code></td><td>包含所有在线价格信息的数组。</td><td>数组</td></tr><tr><td><code>评价</code></td><td>包含评论信息的对象。（仅限美国）</td><td>对象</td></tr><tr><td><code>variants</code></td><td>包含商品变体的对象数组。（颜色、尺寸等）</td><td>数组</td></tr><tr><td><code>related_items</code></td><td>包含相关商品的对象数组。</td><td>数组</td></tr><tr><td><code>specifications</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/google/shopping/broken-reference/README.md"><strong>这里</strong></a>.</td><td>整数</td></tr><tr><td><code>created_at</code></td><td>抓取任务创建时的时间戳。</td><td>timestamp</td></tr><tr><td><code>updated_at</code></td><td>抓取任务完成时的时间戳。</td><td>timestamp</td></tr><tr><td><code>status_code</code></td><td>抓取任务的状态码。你可以查看所描述的抓取器状态码 <a href="https://github.com/oxylabs/gitbook-public-english/blob/master/scraping-solutions/web-scraper-api/targets/google/shopping/broken-reference/README.md"><strong>这里</strong></a>.</td><td>整数</td></tr><tr><td><code>job_id</code></td><td>与抓取任务关联的任务 ID。</td><td>字符串</td></tr></tbody></table>

{% hint style="info" %}
在以下各节中，当结果类型可用的项目多于一个时，已解析的 JSON 代码片段会被截短。
{% endhint %}

### 定价

包含该商品价格信息的对象。

<figure><img src="/files/bdf21e47fc04cd241e59c1c2f3c3250d451a7410" alt=""><figcaption></figcaption></figure>

```json
...
   "pricing": {
    "online": [
        {
          "price": 559,
          "seller": "Walmart - Seller",
          "details": "Pny GeForce RTX 4070 GPU 12gb Xlr8 Gaming Verto Epic-x RGB Triple Fan Dlss 3 Graphics Card",
          "currency": "USD",
          "condition": "全新",
          "seller_link": "https://www.walmart.com/ip/PNY-GeForce-RTX-4070-GPU-12GB-XLR8-Gaming-VERTO-EPIC-X-RGB-Triple-Fan-DLSS-3-Graphics-Card/1396859462?wmlspartner=wlpa&selectedSellerId=101035116&selectedOfferId=159733DADC653E1891C050148D16D747&conditionGroupCode=1",
          "price_shipping": 22.05
        },
...
    ]
},
...
```

<table><thead><tr><th width="231">键（pricing[]）</th><th width="375">描述</th><th>类型</th></tr></thead><tbody><tr><td><code>online</code></td><td>包含该商品定价详情的对象数组。</td><td>数组</td></tr><tr><td><code>online.price</code></td><td>以指定货币表示的商品价格。</td><td>浮点数</td></tr><tr><td><code>online.seller</code></td><td>提供该商品的卖家或商家名称。</td><td>字符串</td></tr><tr><td><code>online.details</code></td><td>关于该商品/购买的其他信息，例如配送和退货政策。</td><td>字符串</td></tr><tr><td><code>online.currency</code></td><td>商品价格所使用的货币代码。</td><td>字符串</td></tr><tr><td><code>online.condition</code></td><td>商品的状况。</td><td>字符串</td></tr><tr><td><code>online.price_tax</code></td><td>应用于商品价格的税额。</td><td>浮点数</td></tr><tr><td><code>online.price_total</code> （可选）</td><td>包含税费在内的商品总价。</td><td>浮点数</td></tr><tr><td><code>online.seller_link</code></td><td>卖家该商品页面的 URL。</td><td>字符串</td></tr><tr><td><code>online.price_shipping</code></td><td>该商品的运费。</td><td>浮点数</td></tr></tbody></table>

### 评论

包含该商品评论和评分信息的对象。

{% hint style="info" %}
目前，评论仅在美国地区可用。
{% endhint %}

<figure><img src="/files/ef4826c0878cc5b204e75afa4c6118493d47ae22" alt=""><figcaption></figcaption></figure>

```json
...       
       "reviews": {
    "rating": 4.7,
    "top_review": {
        "text": "我的电脑是 Dell Optiplex 9020，i7-4770，32MB，500GB SSD。三风扇显卡很长，硬盘架必须拆掉才能装进 Optiplex 机箱。电源升级到了 750 瓦，这需要为 Dell 主板配一个适配器。完成这些改动后，显卡安装得很顺利，不过你得用 Google 去 Nvidia 网站上找驱动。我把这块 GPU 用于 Blender 中的 3D 动画。我对 EEVEE 和 Cycles 中光线追踪渲染速度非常满意。由于这是一台旧电脑，CPU 从未跑到 100%，而且到目前为止我还没能把这块显卡的性能完全榨干。我听不到风扇在转，不过我猜我还没有给它施加过足够高的负载。它在渲染时确实会有一点电子嗡嗡声。\u00a0更少",
        "author": "walmart.com Shopper",
        "rating": 5,
        "source": "Reviewed on walmart.com"
      },
      "rating_stars": 4.7,
      "reviews_count": 51,
      "reviews_by_stars": {
        "1": {
          "reviews_count": 2
        },
        "2": {
          "reviews_count": 0
        },
        "3": {
          "reviews_count": 2
        },
        "4": {
          "reviews_count": 3
        },
        "5": {
          "reviews_count": 44
        }
    },
},
...
```

<table><thead><tr><th width="253">键(reviews[])</th><th width="375">描述</th><th>类型</th></tr></thead><tbody><tr><td><code>rating</code></td><td>商品的平均评分，通常满分为 5。</td><td>浮点数</td></tr><tr><td><code>top_review</code> （可选）</td><td>包含该商品最高评价详情的对象。</td><td>对象</td></tr><tr><td><code>top_review.text</code> （可选）</td><td>最高评价的文本内容</td><td>字符串</td></tr><tr><td><code>top_review.title</code> （可选）</td><td>最高评价的标题。</td><td>字符串</td></tr><tr><td><code>top_review.author</code> （可选）</td><td>最高评价的作者。</td><td>字符串</td></tr><tr><td><code>top_review.rating</code> （可选）</td><td>最高评价作者给出的评分，通常满分为 5。</td><td>浮点数</td></tr><tr><td><code>top_review.source</code> （可选）</td><td>发布最高评价的来源或网站。</td><td>字符串</td></tr><tr><td><code>rating_stars</code></td><td>商品的平均评分，通常满分为 5 星。</td><td>浮点数</td></tr><tr><td><code>reviews_count</code> （可选）</td><td>该商品的评论总数。</td><td>整数</td></tr><tr><td><code>reviews_by_stars</code></td><td>包含各星级评论数量的对象。</td><td>对象</td></tr><tr><td><code>reviews_by_stars.url</code> （可选）</td><td>包含 X 星评论详情的对象。</td><td>字符串</td></tr><tr><td><code>reviews_by_stars.reviews_count</code></td><td>X 星评论的数量。</td><td>整数</td></tr></tbody></table>

### 相关商品（更多选项）

包含目标商品相关商品详情的对象数组。

<figure><img src="/files/b7f9043fdde2446515f8c2c0b46e3e9c908fdb6e" alt=""><figcaption></figcaption></figure>

```json
...             
   "related_items": [
      {
        "items": [
          {
            "url": "/search?ibp=oshop&prds=catalogid:1368129371371338580,gpcid:14975392695437189622,headlineOfferDocid:2388507960063782588,imageDocid:1618178582933849531,productid:7780474142858650836,pvo:2,pvt:hg,rds:PC_14975392695437189622%7CPROD_PC_14975392695437189622&q=nvidia+rtx&gl=us&hl=en&pvorigin=2",
            "image": "https://encrypted-tbn3.gstatic.com/shopping?q=tbn:ANd9GcScO-LIdlqj1WjcLznMECFXNo4qbZ1TRbkfHdDsDPoIYxx7S9TjKhnQX7Ah6QsKI-zPBKFrC54H0wGZC60Q_NdRebesvYUXwRhQFuZRwvtWmx4_0xoxbylM",
            "price": 639.99,
            "title": "NVIDIA GeForce RTX 5070 12GB GDDR7 显卡",
            "currency": "USD",
            "reviews_count": 228
          },
...
        ],
        "title": "更多选项"
     }
],
...
```

<table><thead><tr><th width="265">键(related_items[])</th><th width="350">描述</th><th>类型</th></tr></thead><tbody><tr><td><code>项目</code></td><td>包含每个相关商品详情的对象数组。</td><td>数组</td></tr><tr><td><code>items.url</code></td><td>相关商品页面的 URL。</td><td>字符串</td></tr><tr><td><code>items.image</code></td><td>相关商品图片的 URL。</td><td>字符串</td></tr><tr><td><code>items.price</code></td><td>相关商品以指定货币表示的价格。</td><td>浮点数</td></tr><tr><td><code>items.title</code> （可选）</td><td>相关商品列表的标题。</td><td>字符串</td></tr><tr><td><code>items.rating</code> （可选）</td><td>相关商品的平均用户评分，通常满分为 5。</td><td>整数</td></tr><tr><td><code>items.store</code> （可选）</td><td>提供相关商品的商店或商家名称。</td><td>字符串</td></tr><tr><td><code>items.currency</code></td><td>商品价格所使用的货币代码。</td><td>字符串</td></tr><tr><td><code>items.reviews_count</code></td><td>相关商品的评论总数。</td><td>整数</td></tr><tr><td><code>title</code></td><td>相关商品部分的标题或标题文本</td><td>字符串</td></tr></tbody></table>

### 规格

包含该商品规格详情的对象数组。

<figure><img src="/files/a25c1cfc47688d76fd6d2d269291abd2d373e5b1" alt=""><figcaption></figcaption></figure>

```json
...
"specifications": [
    {
        "items": [
          {
            "title": "制造商",
            "value": "PNY"
          },
          {
            "title": "输出",
            "value": "HDMI, DisplayPort"
          },
          {
            "title": "接口",
            "value": "PCI Express"
          },
          {
            "title": "品牌",
            "value": "PNY"
          },
...
        ],
        "section_title": "attributes"
      }
],
...
```

<table><thead><tr><th width="220">键（specifications[]）</th><th width="367">描述</th><th>类型</th></tr></thead><tbody><tr><td><code>项目</code></td><td>包含各项规格详情的对象数组。</td><td>数组</td></tr><tr><td><code>items.title</code></td><td>规格名称。</td><td>字符串</td></tr><tr><td><code>items.value</code></td><td>规格的值。</td><td>字符串</td></tr><tr><td><code>section_title</code></td><td>规格部分的标题或标题文本</td><td>字符串</td></tr></tbody></table>


---

# 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/api-targets/cn/sou-suo-yin-qing/google/shopping/shopping-product.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.
