boyenec
boyenec

Reputation: 1617

selenium python why I am not getting image url?

I am trying to get all gallary image url from this page. Every product have multiple images. here is my code where I am trying to get image url:

img = driver.find_elements_by_css_selector('.gem-gallery-thumbs-carousel img')
for i in img:
    y = i.get_attribute('href')
    print(y)

result:     
None
None
None
None
None
None

Upvotes: 0

Views: 220

Answers (2)

Arundeep Chohan
Arundeep Chohan

Reputation: 9969

To output the srcs for those you need to .get_attribute() for src

wait=WebDriverWait(driver, 60)
driver.get('https://ca.morilee.com/product/quinceanera-dresses/vizcaya/iridescent-crystal-beaded-quinceanera-dress/')
imgs=wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,".gem-gallery-thumbs-carousel img")))
for img in imgs:
    print(img.get_attribute("src")

Imports:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

Outputs:

https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0259-scaled-1-280x400.jpg
https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0292-scaled-1-280x400.jpg
https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0061-scaled-1-280x400.jpg
https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0083-scaled-1-280x400.jpg
https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0101-scaled-1-280x400.jpg
https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0196-scaled-1-280x400.jpg

Upvotes: 1

Prophet
Prophet

Reputation: 33361

  1. The image urls in those elements are contained in src attribute, not in href as mentioned in comments.
  2. You probably should add wait / delay to make the page loaded before reading the elements contents.
    So, something like this After appropriate wait / delay should work:
imgs = driver.find_elements_by_css_selector('.gem-gallery-thumbs-carousel img')
for img in imgs:
    url = img.get_attribute('src')
    print(url)

Upvotes: 1

Related Questions