我正在使用 SerpAPI Google 搜索来查找购物结果,并且我一直在尝试找到一种方法来限制我的搜索结果来自特定的网站列表。我找不到任何可以在 API 中设置的直接参数。
我尝试检查 JSON 响应的“链接”部分中的网站名称,但也没有成功。有什么推荐吗?
正如 @juanpethes 提到的,对 Google Search API 执行此操作的最佳方法是将
site:domain.com
添加到您的 q
参数中。例如:q=Coffee site:amazon.com OR walmart.com
既然您提到了购物结果,我应该注意Google Shopping不支持这些
site:domain.com
类型的过滤器。相反,您需要引用 SerpApi 在对 Google Shopping API 的请求中返回的 filters
数组。 filters
中有多个选项,包括 Stores
,它们提供了一些您也可以过滤结果的商店。
不幸的是,这些仅限于 Google Shopping 为任何给定搜索提供的内容。您无法过滤任意您想要的商店。这是 Google 的限制,SerpApi 无法解决。
例如:
https://serpapi.com/playground?engine=google_shopping&q=咖啡
"filters: [
...
{
"type": "Stores",
"options":
[
{
"text": "Target",
"serpapi_link": "https://serpapi.com/search.json?device=desktop&engine=google_shopping&gl=us&google_domain=google.com&hl=en&q=target+coffee&shoprs=CAEYAioGY29mZmVlMgoIAhIGVGFyZ2V0WLfLH2AC"
}
,
{
"text": "Walmart",
"serpapi_link": "https://serpapi.com/search.json?device=desktop&engine=google_shopping&gl=us&google_domain=google.com&hl=en&q=walmart+coffee&shoprs=CAEYAioGY29mZmVlMgsIAhIHV2FsbWFydFi3yx9gAg"
}
,
{
"text": "Home Depot",
"serpapi_link": "https://serpapi.com/search.json?device=desktop&engine=google_shopping&gl=us&google_domain=google.com&hl=en&q=home+depot+coffee&shoprs=CAEYAioGY29mZmVlMg4IAhIKSG9tZSBEZXBvdFi3yx9gAg"
}
,
{
"text": "Sears",
"serpapi_link": "https://serpapi.com/search.json?device=desktop&engine=google_shopping&gl=us&google_domain=google.com&hl=en&q=sears+coffee&shoprs=CAEYAioGY29mZmVlMgkIAhIFU2VhcnNYt8sfYAI"
}
]
}
...
]
使用
serpapi_link
作为您要筛选的商店,以仅获取该商店的结果。您只需将您的 api_key
附加到请求中即可。
免责声明:我为 SerpApi 工作。