Python: How to Save Image from URL


If you have a web URL for an Image and you want to save it to a specific location using Python then you can make use of the requests module.

The first thing is you should make sure that you have installed the requests module using pip.

pip install requests
pip3 install requests

Example:

import requests

image_url = "https://code2care.org/c2c-img/icons/python.png"

image_content = requests.get(image_url).content

with open('python.png', 'wb') as handler:
    handler.write(image_content)
How to Save an Image from URL in Python Example
-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap