def download(dest_path, url):
try:
file_name = url.split('/')[-1]
path = os.path.realpath(os.path.join(dest_path, unquote_plus(file_name)))
if not os.path.exists(path):
f = urlopen(url)
headers = f.headers['content-type'].split('/')
md = 'w'
if 'html' in headers:
file_name = '{}.html'.format(uuid.uuid1())
else:
md = 'wb'
with open(path, md) as local_file:
local_file.write(f.read())
if os.path.exists(path):
return path
else:
logger.info("Wasn't able to find the file....!")
return None
except Exception as error:
logger.error('download error %s', error)
评论列表
文章目录