Google 搜索 API - 仅返回 4 个结果
经过大量实验和谷歌搜索,以下 Python 代码成功调用了 Google 的搜索 APi - 但只返回 4 个结果:在阅读了 Google 搜索 API 文档后,我认为 'start=' 会返回其他结果:但这并没有发生。
有人可以指点一下吗?谢谢。
Python代码:
/usr/bin/python
import urllib
import simplejson
query = urllib.urlencode({'q' : 'site:example.com'})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s&start=50' \
% (query)
search_results = urllib.urlopen(url)
json = simplejson.loads(search_results.read())
results = json['responseData']['results']
for i in results:
print i['title'] + ": " + i['url']
After much experimenting and googling, the following Python code successfully calls Google's Search APi - but only returns 4 results: after reading the Google Search API docs, I thought the 'start=' would return additional results: but this not happen.
Can anyone give pointers? Thanks.
Python code:
/usr/bin/python
import urllib
import simplejson
query = urllib.urlencode({'q' : 'site:example.com'})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s&start=50' \
% (query)
search_results = urllib.urlopen(url)
json = simplejson.loads(search_results.read())
results = json['responseData']['results']
for i in results:
print i['title'] + ": " + i['url']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
开始选项不会为您提供更多结果,它只会让您向前移动许多结果。将结果视为一个队列。从 50 开始将为您提供结果 50、51、52 和 53。
这样,您可以通过从每 4 个结果开始获得更多结果:
The start option doesn't give you more results, it just moves you forward that many results. Think of the results as a queue. Starting at 50 will give you results 50, 51, 52, and 53.
With this you can get more results by starting every 4th result: