我通过 python 使用 google api 并且它可以工作,但是我从 api 得到的结果与 google.com 完全不同。我发现自定义搜索给出的最高结果是谷歌日历、谷歌地球和专利。我想知道是否有办法从自定义搜索 api 获得相同的结果。谢谢
def googleAPICall(self,userInput):
try:
userInput = urllib.quote(userInput)
for i in range(0,1):
index = i*10+1
url = ('https://www.googleapis.com/customsearch/v1?'
'key=%s'
'&cx=%s'
'&alt=json'
'&num=10'
'&start=%d'
'&q=%s')%(self.KEY,self.CX,index,userInput)
print (url)
request = urllib2.Request(url)
response = urllib2.urlopen(request)
returnResults = simplejson.load(response)
webs = returnResults['items']
for web in webs:
self.result.append(web["link"])
except:
print ("search error")
self.result.append("http://en.wikipedia.org/wiki/Climate_change")
return self.result
请您参考如下方法:
仪表板中有一个“在 google 之外搜索”复选框。检查后你会得到相同的结果。我花了一些时间才找到它。默认设置只返回所有谷歌网站内的搜索结果。
