Created
October 30, 2011 14:31
-
-
Save papachan/1325961 to your computer and use it in GitHub Desktop.
python download url and save it to your compputer from a txt file
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 os | |
import os.path | |
import time | |
import urllib2 | |
import codecs | |
# python download url and save it to your compputer from a txt file | |
dirname = "/Users/papachan/Desktop/site/static/" | |
filename = "url.txt" | |
file = open(filename, 'r') | |
for url in file.readlines(): | |
myfile = urllib2.urlopen(url) | |
list = url.split('/')[3:] | |
pathname = '/'.join(list) | |
filename = dirname + pathname | |
output = open(filename,'wb') | |
output.write( codecs.BOM_UTF8 ) | |
output.write(myfile.read()) | |
output.close() | |
if(os.path.exists(filename)): | |
print os.path.abspath(filename) | |
else: | |
print "Error file didnt save" | |
time.sleep(2) | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment