谷歌customsearch返回不同的结果?

2024-09-25 00:22:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用googlecustomsearch api来搜索图像,但奇怪的是,我通过api进行的搜索返回的结果与通过浏览器常规搜索的结果不同。例如

from apiclient.discovery import build
import pprint
import sys
api_key='xxxxxxx'
service = build('customsearch', 'v1', developerKey=api_key)
request=service.cse()
query=request.list(cx='xxxx:xxxxx',q='dogs and cats',searchType='image',imgType='photo')
result=query.execute()
pprint.pprint(result)
for i in result.get('items',[]):
    print (i['link'])

运行这段代码会得到完全不同的结果 下面是运行上述代码的结果

^{pr2}$

这是一个来自chrome的google搜索快照 enter image description here 问题是一样的,有人知道为什么吗?在


Tags: key代码from图像importbuildapirequest
3条回答

这取决于您从google控制台创建的自定义搜索引擎。转到谷歌控制台上的CSE,尝试“在web上查看”选项,在浏览器中测试它,看看结果是否匹配。结果应该匹配。在

你正常的谷歌搜索将基于谷歌收集到的大量关于你的信息。在

你正常的谷歌搜索将基于谷歌收集到的大量关于你的信息。如果你退出google并使用一个匿名窗口,它应该不会受到影响。在

相关问题 更多 >