I want to extract top 50 results from google search and get the title and snippet for each search result. I am using the following code.
#!/usr/bin/python3
import json
import urllib.request, urllib.parse
def showsome(searchfor):
query = urllib.parse.urlencode({'q': searchfor})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query
search_response = urllib.request.urlopen(url)
search_results = search_response.read().decode("utf8")
results = json.loads(search_results)
data = results['responseData']
print('Total results: %s' % data['cursor']['estimatedResultCount'])
print(data['results'])
hits = data['results']
print('Top %d hits:' % len(hits))
print(hits)
for h in hits:
print(' ',h['title'])
print(' ', h['url'])
showsome('jaguar')
But I am only getting 4 results. ie the results before the image search comes on search results page. Can someone please suggest a better method for this task. It will be better if you can give a genereal way which can work on other search engines also like say yahoo.com