Beatifulsoup: How To Get Image Size By Url
I need to get width and height if the extracted image url, i used get('width'), but this seems not working description = soup.find('div', id='module_product_detail') img= descripti
Solution 1:
Since there's not width nor height attribute, the only way to access the METADATA of the image is by downloading it and reading it like this:
from requests import get
from io import BytesIO
from PIL import Image
image_raw = get('https://upload.wikimedia.org/wikipedia/commons/3/30/Googlelogo.png')
image = Image.open(BytesIO(image_raw.content))
width, height = image.size
print(width, height)
# Output:
# 1368 469
Post a Comment for "Beatifulsoup: How To Get Image Size By Url"