Last active
May 3, 2018 01:59
-
-
Save qzcool/d42bca05a98e8344a9d22bd30411cb4e to your computer and use it in GitHub Desktop.
[Python 3.6] Download File Common Function
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
# Download File Common Function | |
def download_file(url, path): | |
local_filename = url.split('/')[-1] | |
# NOTE the stream=True parameter | |
r = requests.get(url, stream=True) | |
with open(local_filename, 'wb') as f: | |
for chunk in r.iter_content(chunk_size=1024): | |
if chunk: # filter out keep-alive new chunks | |
f.write(chunk) | |
#f.flush() commented by recommendation from J.F.Sebastian | |
shutil.move(local_filename,path+'/'+local_filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment