Created
February 19, 2014 09:08
-
-
Save mvpotter/9088499 to your computer and use it in GitHub Desktop.
Download large files using python
This file contains hidden or 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
def download_file(url): | |
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() | |
return local_filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can try this: https://gist.github.com/hossainel/0d36a86246c83dc406897464cfc5b460