how to download file in python

Do you want to know the details about “how to download file in python”. If yes, you’re in the correct tutorial.

how to download file in python

import urllib2

filedata = urllib2.urlopen('http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg')
datatowrite = filedata.read()
 
with open('/Users/scott/Downloads/cat2.jpg', 'wb') as f:
    f.write(datatowrite)
import urllib.request

print('Beginning file download with urllib2...')

url="http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg"
urllib.request.urlretrieve(url, '/Users/scott/Downloads/cat.jpg')

Conclusion

I hope this post helps you to know about “how to download file in python”. If you have any doubts regarding this post please let us know via the comment section. Share this post with your friends and family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment