Skip to content

Instantly share code, notes, and snippets.

@empireshades
Created May 22, 2015 19:35
Show Gist options
  • Save empireshades/505bb964799348dbc3f4 to your computer and use it in GitHub Desktop.
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
# 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