0

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
4
  • 1
    Images typically have a src attribute, not href. And on that page in particular, it looks like they have a data-tgpli-src attribute. Commented Dec 9, 2021 at 20:45
  • John Gordon I know and tried but didn't work Commented Dec 9, 2021 at 20:46
  • Update the question to include a sample of the element you are expecting to find. Commented Dec 9, 2021 at 20:47
  • 1
    John Gordon Thanks. it worked now after changing href to src but didn't understood why it wasn't working before. By the way thanks. Commented Dec 9, 2021 at 20:49

2 Answers 2

1
  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)
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.