Sometimes, we want to download a picture via urllib and Python.
In this article, we’ll look at how to download a picture via urllib and Python.
How to download a picture via urllib and Python?
To download a picture via urllib and Python, we can use the urllib.request.urlretrieve
method.
For instance, we write
import urllib.request
urllib.request.urlretrieve("https://picsum.photos/200/300", "pic.jpg")
to call urllib.request.urlretrieve
with the URL of the image and the file name to save it as.
Conclusion
To download a picture via urllib and Python, we can use the urllib.request.urlretrieve
method.