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 Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

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