karen
karen

Reputation: 1

Why does selenium do not download the images?

In this code, im trying to download images from a page but it does not download them,i did it once but not anymore, i do not know what is bad here

from selenium import webdriver
from selenium.webdriver.common.by import By
import requests
from PIL import Image
from io import BytesIO

driver = webdriver.Firefox()

driver.get("https://anilist.co/search/anime?genres=Action&format=TV")

image_element = driver.find_element(By.CSS_SELECTOR, "image.loaded")

image_src = image_element.get_attribute("src")

response = requests.get(image_src)

if response.status_code == 200:

    image = Image.open(BytesIO(response.content))

    image.save("imagen-1.jpg")

    print("works")
else:
    print("didnt work")

driver.quit()

the class of the image is image loaded, i added the dot,

I tried to put and remove the dot but is the same thing, i dont know what is happening

Upvotes: 0

Views: 50

Answers (1)

Mohil Patel
Mohil Patel

Reputation: 510

Use .image.loaded since you are using CSS selector. The line should look something like

image_element = driver.find_element(By.CSS_SELECTOR, ".image.loaded")

Upvotes: 0

Related Questions