Created
November 16, 2014 20:11
-
-
Save viperscape/05f6158d82cb02952407 to your computer and use it in GitHub Desktop.
nasa-apod download
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
import urllib.request | |
address = 'http://apod.nasa.gov/apod/astropix.html' | |
file = urllib.request.urlopen(address) #read in the site and hunt for the image url | |
html = file.read() | |
data = html.decode('utf-8') | |
#print (data) | |
s = data.find("<a href=\"image")+14 #find the first instance of the image hyperlink | |
e = data.find("\"",s) #find the end of this hyperlink | |
iurl = "http://apod.nasa.gov/image" + data[s:e] #slice out the image url and tack on the full url | |
print (iurl) | |
i = data[s:e].split('/') | |
urllib.request.urlretrieve(iurl,'/home/chris/Backgrounds/NASA/'+i[len(i)-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment