Google搜索API-仅返回4个结果 [英] Google Search API - Only returning 4 results

查看:122
本文介绍了Google搜索API-仅返回4个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过大量实验和谷歌搜索,以下Python代码成功调用了Google的Search APi-但仅返回4个结果:阅读Google Search API文档后,我认为'start ='将返回其他结果:但这不会发生.

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代码:

/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']

推荐答案

start选项不会给您更多的结果,它只是使您前进那么多结果.将结果视为一个队列.从50开始,您将获得50、51、52和53的结果.

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.

这样,您可以通过每第4个结果开始获得更多结果:

With this you can get more results by starting every 4th result:

import urllib
import simplejson

num_queries = 50*4 
query = urllib.urlencode({'q' : 'example'})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query

for start in range(0, num_queries, 4):
    request_url = '{0}&start={1}'.format(url, start)
    search_results = urllib.urlopen(request_url)
    json = simplejson.loads(search_results.read())
    results = json['responseData']['results']
    for i in results:
        print i['title'] + ": " + i['url']

这篇关于Google搜索API-仅返回4个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆