Answers for "python requests how to write images to variable"

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

Code answers related to "python requests how to write images to variable"

Python Answers by Framework

Browse Popular Code Answers by Language