Skip to content

Instantly share code, notes, and snippets.

@whiteclover
Last active December 19, 2015 04:38
Show Gist options
  • Save whiteclover/5898219 to your computer and use it in GitHub Desktop.
Save whiteclover/5898219 to your computer and use it in GitHub Desktop.
google ajax search
#!/usr/bin/python3
import json
import urllib.request, urllib.parse
def google_ajax_search(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'])
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'])
google_ajax_search('ermanno olmi')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment