0

嗨,我正在用 php 抓取谷歌购物结果(使用 curl 和简单的 html dom 库)。一切都很好,我得到了我所在国家/地区的商店的结果,然后我将代码上传到了谷歌云(谷歌应用引擎),并且抓取的结果有所不同(不在我所在国家/地区的商店),就好像结果是从另一个谷歌域名(另一个国家)获取的

这是我使用的链接https://www.google.com.sa/search?q=coffee&safe=images&tbm=shop 我试图编辑 hl,gl 但它不起作用。

有人说要更改 http 标头“接受的语言”,但这也没有用

所以我的问题是当我从谷歌云运行代码时如何获得相同的结果

4

2 回答 2

0

查看对 Google Shopping 的支持,根据此链接似乎不再支持此功能。

您可以尝试在离您所在位置较近的区域使用 App Engine 创建一个不同的项目。您可以在此处找到位置列表。

希望您觉得这个有帮助。

于 2020-02-05T09:11:56.647 回答
0

您也可以尝试传递uule参数,即加密的 Google 位置参数。

例如w+CAIQICIaQXVzdGluLFRleGFzLFVuaXRlZCBTdGF0ZXM(奥斯汀,德克萨斯州,美国)

您可以在此处阅读更多相关信息:https ://blog.linkody.com/seo-local/uule-2


或者,您可以使用第三方解决方案,例如 SerpApi。这是一个免费试用的付费 API。

示例 php 代码(也可在其他库中获得):

require 'path/to/google_search_results';

$query = [
  "api_key" => "secret_api_key",
  "engine" => "google",
  "q" => "coffee",
  "location" => "Austin, Texas, United States",
  "google_domain" => "google.com",
  "gl" => "us",
  "hl" => "en",
  "tbm" => "shop"
];

$search = new GoogleSearch();
$results = $search->json($query);

示例 JSON 输出:

"inline_shopping_results": [
  {
    "position": 1,
    "block_position": "top",
    "title": "Hazelnut & French Vanilla Bundle (30% Off) 12 oz Beans",
    "price": "$47.95",
    "extracted_price": 47.95,
    "link": "https://www.google.com/aclk?sa=l&ai=DChcSEwjO8tWjiabxAhUDU3IKHUrrC5cYABAEGgJxdQ&sig=AOD64_3Ui55ttgZqIqcfG24uwghjpEXZ3w&ctype=5&q=&ved=0ahUKEwjI49CjiabxAhUCVc0KHbKhD-4Qww8I9Qo&adurl=",
    "source": "lifeboostcoffee.com",
    "shipping": "Free shipping",
    "thumbnail": "https://encrypted-tbn1.gstatic.com/shopping?q=tbn:ANd9GcQNspCBgGMVst_bukmSUPgfCrhshOZOkMMFaIVsJjlcr6P5RR7QfwcGiLzBc1jiKq_LzbgwhM2ZSjqc9p3Tr4h1KjgMbTccri-v6uIXamyMCjrMONPdN0DWyg&usqp=CAE"
  },
  ...
],
"shopping_results": [
  {
    "position": 1,
    "title": "Black Rifle Coffee Company Freedom Fuel Coffee Roast 12oz. Ground4.01Ground · Dark Roast · Bag",
    "link": "https://www.google.com/aclk?sa=L&ai=DChcSEwjO8tWjiabxAhUDU3IKHUrrC5cYABA2GgJxdQ&sig=AOD64_2h8ptBTClONQYS9yOHV7RdLQjwbw&ctype=5&q=&ved=0ahUKEwjI49CjiabxAhUCVc0KHbKhD-4Qg-UECN8L&adurl=",
    "product_link": "https://google.com/shopping/product/18134019833504388210",
    "product_id": "18134019833504388210",
    "serpapi_product_api": "https://serpapi.com/search.json?device=desktop&engine=google_product&gl=us&google_domain=google.com&hl=en&location=Austin%2C+Texas%2C+United+States&product_id=18134019833504388210",
    "source": "Black Rifle Coffee Company",
    "price": "$13.99",
    "extracted_price": 13.99,
    "rating": 4,
    "reviews": 1,
    "snippet": "Ground · Dark Roast · Bag",
    "thumbnail": "https://serpapi.com/searches/60cf21bbea1442598e2972d1/images/c54459381b000cca098e49139db83d19bde8b72d3bef4a5544e7fad26ff7169d.webp"
  },
  ...
]

查看文档以获取更多详细信息。

免责声明:我在 SerpApi 工作。

于 2021-06-20T11:24:01.647 回答