Created
May 22, 2015 19:35
-
-
Save empireshades/505bb964799348dbc3f4 to your computer and use it in GitHub Desktop.
Iterate through list of terms, google image search each, and display results in ipython notebook inline
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
# Yes i know i could have used Requests | |
import urllib2 | |
import json | |
from IPython.display import display | |
from IPython.display import Image | |
for car in yearlist: | |
url = ('https://ajax.googleapis.com/ajax/services/search/images?' + | |
'v=1.0&rsz=8&q=%s') % car.replace(" ", "%20") | |
request = urllib2.Request(url, None, {'Referer': "http://blah.org"}) | |
response = urllib2.urlopen(request) | |
results = json.load(response) | |
pics = [i['url'] for i in results['responseData']['results']][0:2] | |
print car | |
for pic in pics: | |
display(Image(url=pic)) | |
print "------------------------------------------------\n\n\n\n\n\n" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment