我正在尝试使用Google自定义搜索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'])
运行这段代码会得到完全不同的结果 这是运行上述代码的结果
https://s.yimg.com/ny/api/res/1.2/tarWzt2ZXfPOEg8oQVlOWw--/YXBwaWQ9aGlnaGxhbmRlcjtzbT0xO3c9ODAw/http://media.zenfs.com/en-US/homerun/people_218/4d82a5fa19dd37247717704975fdf602
https://www.google.com/about/main/machine-learning-qa/img/cat-dog-flow-horizontal.gif
https://www.google.com/trends/2014/static/images/pets-snapshot-reveal-1920.jpg
https://www.google.com/trends/2014/static/images/pets-share.png
https://www.google.com/about/main/machine-learning-qa/img/cat-dog-flow-vertical.gif
https://s.yimg.com/uu/api/res/1.2/YQWuQgTnzQuwXjYzX.QrWg--~B/aD0xMzMzO3c9MjAwMDtzbT0xO2FwcGlkPXl0YWNoeW9u/http://media.zenfs.com/en-US/homerun/people_218/4d82a5fa19dd37247717704975fdf602
https://www.google.com/trends/2014/static/images/pets-video-1080.jpg
https://www.google.com/trends/2014/static/images/pets-video-320.jpg
https://www.google.com/maps/d/thumbnail?mid=1hO0YkGLATyy-ZI9JxX1lbv-wK1M&hl=en_US