Skip to content

Instantly share code, notes, and snippets.

Created January 2, 2015 07:46
Show Gist options
  • Save anonymous/b5a4176a5ae4951cd0c8 to your computer and use it in GitHub Desktop.
Save anonymous/b5a4176a5ae4951cd0c8 to your computer and use it in GitHub Desktop.
from urllib2 import urlopen
import urllib
import requests
import urllib2
import urllib
import pdb
import os
import sys
import time
import lxml.html
from lxml.cssselect import CSSSelector
from lxml.html import parse
import urlparse
r = requests.get('http://www.jpl.nasa.gov/spaceimages/')
parsed= lxml.html.fromstring(r.text)
images=parsed.xpath('//img/@src')
if not images:
sys.exit("found no pictures")
images = [urlparse.urljoin(r.url, url) for url in images]
#pdb.set_trace()
def getImages(r):
print 'found %s pictures' % len(images)
print "test"
for url in images:
urllib.urlretrieve(url)
print "downloading!!"
getImages(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment