Created
January 2, 2015 07:46
-
-
Save anonymous/b5a4176a5ae4951cd0c8 to your computer and use it in GitHub Desktop.
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
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