-1

How to extract the this address using Selenium and Python

HTML:

<span class="mrehover dn" id="morehvr_add_cont0">
    <span class="blckarw"></span>
    <span class="cont_fl_addr">60-B, J D Alves Premises, Hill Road, Bandra West, Mumbai - 400050, Next to Bandra Medical Store</span>
</span>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

0

you can use CSS selector span.cont_fl_addr if you dont like XPATH

Roman
  • 1,883
  • 2
  • 14
  • 26
0

To print the address 60-B, J D Alves Premises, Hill Road, Bandra West, Mumbai - 400050, Next to Bandra Medical Store you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using XPATH and text attribute:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//span[@class='cont_fl_addr']"))).text)
    
  • Using CSS_SELECTOR and get_attribute():

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "span.cont_fl_addr"))).get_attribute("innerHTML"))
    
  • 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
    

You can find a relevant discussion in How to retrieve the text of a WebElement using Selenium - Python


Outro

Link to useful documentation:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352