Last active
December 19, 2015 04:38
-
-
Save whiteclover/5898219 to your computer and use it in GitHub Desktop.
google ajax search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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