def download_file(my_URL, my_outfile = ''):
# function to download a file from a URL
# !! This will overwrite the output file
# https://gist.github.com/hughdbrown/c145b8385a2afa6570e2
import urllib2
import urlparse
import os
URL_basename = os.path.basename(urlparse.urlsplit(my_URL).path)
# if no output file specified, save to URL filename in current dir
if my_outfile == '':
my_outfile = URL_basename
my_URL = urllib2.urlopen(my_URL)
with open(my_outfile, 'wb') as output:
while True:
data = my_URL.read(4096) # download in chunks
if data:
output.write(data)
else:
break
评论列表
文章目录