Skip to content

Instantly share code, notes, and snippets.

@eszterkv
Created September 9, 2016 09:08
Show Gist options
  • Save eszterkv/6357d9f6d7d00c9874ebd6e0316777f3 to your computer and use it in GitHub Desktop.
Save eszterkv/6357d9f6d7d00c9874ebd6e0316777f3 to your computer and use it in GitHub Desktop.
Downloads the file on the given url and saves it to the current directory.
#!/usr/bin/env python3
import os
import os.path
import requests
def dl(url):
'''
Downloads the file on the given url and saves it to the current directory.
'''
r = requests.get(url)
if r.status_code >= 400:
print('File not found at URL %s' % url)
return
filename = url.split('/')[-1]
with open(filename, 'wb') as f:
f.write(r.content)
print('Successfully downloaded %s from %s/' % (filename, ('/').join(url.split('/')[:-1])))
f.close()
if __name__ == '__main__':
url = input('Enter URL of the file to download: ')
dl(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment