1

I'm trying to get all the links of the images from the below mentioned html code type:

<a href="#!" class="elevatezoom-gallery" data-update="" data-image="https://img.xyz.com/rcmshopping/PROD_IMAGES/fffff_2018_05_10_10_49_23.jpg" data-zoom-image="https://img.xyz.com/rcmshopping/PROD_IMAGES/fffff_2018_05_10_10_49_23.jpg"> <img src="https://img.xyz.com/rcmshopping/PROD_IMAGES/fffff_2018_05_10_10_49_23.jpg"> </a>

I am not able to fetch any link from this part of html out f 3 any 1 is good for me. Im new to python please guide.

2 Answers2

1

To print the value of the src attribute you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using XPATH:

    print(WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[@class='elevatezoom-gallery']/img"))).get_attribute("src"))
    
  • Using CSS_SELECTOR:

    print(WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a.elevatezoom-gallery>img"))).get_attribute("src"))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You can achieve that by using the find_elements_by_css_selector() function.

links = self.webdriver.find_elements_by_css_selector('img[src="https://img.xyz.com/rcmshopping/PROD_IMAGES/fffff_2018_05_10_10_49_23.jpg"])
Aleksander Ikleiw
  • 2,549
  • 1
  • 8
  • 26
  • Thanks for your response.. actually I want to extract all the image links (img.xyz.com/rcmshopping/PROD_IMAGES/fffff_2018_05_10_10_49_23.jpg) so how can I put in the link only in code – iAM BEAUTIFUL Jul 18 '20 at 19:34
  • the use `self.webdriver.find_elements_by_class_name('elevatezoom-gallery').get_attribute('src')` – Aleksander Ikleiw Jul 18 '20 at 19:38