def download(url, filename, overwrite=False, timeout=None):
"""
Download the given URL to the given filename. If the file exists,
it won't be downloaded unless asked to overwrite. Both, text data
like html, txt, etc. or binary data like images, audio, etc. are
acceptable.
:param url: A URL to download.
:param filename: The file to store the downloaded file to.
:param overwrite: Set to True if the file should be downloaded even if it
already exists.
"""
if not os.path.exists(filename) or overwrite:
if timeout is None:
response = urlopen(url)
else:
response = urlopen(url, timeout=timeout)
with open(filename, 'wb') as out_file:
copyfileobj(response, out_file)
评论列表
文章目录