how to download file in python

Solutions on MaxInterview for how to download file in python by the best coders in the world

showing results for - "how to download file in python"
Angelo
04 Nov 2020
1import urllib2
2
3filedata = urllib2.urlopen('http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg')
4datatowrite = filedata.read()
5 
6with open('/Users/scott/Downloads/cat2.jpg', 'wb') as f:
7    f.write(datatowrite)
8
Leni
18 Aug 2017
1import urllib.request
2
3print('Beginning file download with urllib2...')
4
5url = 'http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg'
6urllib.request.urlretrieve(url, '/Users/scott/Downloads/cat.jpg')
7