Answers for "python requests get image"

2

requests get image from url

import requests
import io
from PIL import Image

response = requests.get("https://i.imgur.com/ExdKOOz.png")
image_bytes = io.BytesIO(response.content)

img = Image.open(image_bytes)
print(f'Size: {img.size}')
img.show()
Posted by: Guest on July-18-2021
2

requests download image

response = requests.get("https://i.imgur.com/ExdKOOz.png")

file = open("sample_image.png", "wb")
file.write(response.content)
file.close()
Posted by: Guest on May-25-2020
1

save image requests python

import requests

url = 'http://google.com/favicon.ico'
r = requests.get(url, allow_redirects=True)
open('google.ico', 'wb').write(r.content)
Posted by: Guest on February-01-2020
0

save image requests python

import requests

def is_downloadable(url):
    """
    Does the url contain a downloadable resource
    """
    h = requests.head(url, allow_redirects=True)
    header = h.headers
    content_type = header.get('content-type')
    if 'text' in content_type.lower():
        return False
    if 'html' in content_type.lower():
        return False
    return True

print(is_downloadable('https://www.youtube.com/watch?v=9bZkp7q19f0'))
# >> False
print(is_downloadable('http://google.com/favicon.ico'))
# >> True
Posted by: Guest on February-01-2020

Python Answers by Framework

Browse Popular Code Answers by Language