I am trying to get the images from one webpage, but I am not being able to solve it. I am getting an error message saying:
"cannot identify image file <_io.BytesIO object at 0x00000270FA2A27C0>"
I read other posts but I was not able to find a solution.
The webpage I am using has this formatting:
So the print of "image2" recognizes the URL of the JPG properly, but it is not possible through the other work, as it says: cannot identify image file <_io.BytesIO object at 0x00000270FA2A27C0> What am I doing wrong?
In the following, I have written:
import requests from PIL import Image # pip install Pillow import io from selenium import webdriver # pip install selenium from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By opts = Options() driver = webdriver.Chrome('./chromedriver.exe', options=opts) image2 = driver.find_element(By.XPATH, '//figure[@class="gallery__image"]/img').get_attribute('src') print (image2) #IMAGE url = driver.find_element_by_xpath('//figcaption/a') url = url.get_attribute('href') # obtengo el URl de la imagen del anuncio # con requests, hago el requerimiento a la URL de la imagen image_content = requests.get(url).content image_file = io.BytesIO(image_content) image = Image.open(image_file).convert('RGB') file_path = 'D:\imagenescode\Alemania\Bayern/' + str(i).replace('.png','').replace('/','').replace('?','').replace(':','') + '.jpg' # nombre a guardar de la imagen with open(file_path, 'wb') as f: image.save(f, "JPEG", quality=85)
https://stackoverflow.com/questions/66996038/how-could-i-download-the-images-in-selenium-when-the-bytesio-error-occur April 08, 2021 at 09:06AM
没有评论:
发表评论