I am trying to write a Python 3 function that works like the following:
links = google_search('"done" "store"')
for l in links: print(l)
The output should be a very long list, something like:
www.cnn.com/articles/done_with_sotres.html
www.something.org/whatever?p=bla
.
.
.
I found this suggestion, Google Search from a Python App, but I seem to get only 4 urls in "hits", and I am unsure how to get the rest. any suggestion will be highly appreciated!
EDIT: stupid me! I didn't put the implementation. anyway, it's the one described in the link:
def search(search_string):
query = urllib.parse.urlencode({'q': search_string})
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'])
hits = data['results']
print('Top %d hits:' % len(hits))
for h in hits: print(' ', h['url'])
print('For more results, see %s' % data['cursor']['moreResultsUrl'])
return hits