Google Search API - returns only 4 results

After a lot of experimentation and searching on Google, the following Python code successfully calls the Google Search APi, but returns only 4 results: after reading the Google Search API documents, I thought that "start =" would return additional results: but this will not happen.

Can pointers be given? Thank.

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']
+3
source share
1 answer

The launch option does not give you more results; it just takes you forward that many results. Think of the results as a queue. Starting at 50, you will get results of 50, 51, 52, and 53.

With this, you can get more results, starting every fourth 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']
+2

Source: https://habr.com/ru/post/1781577/


All Articles