Skip to content Skip to sidebar Skip to footer

How To Get Specific Text That Belongs To Div Class

Firstly I am gettin datas from a website and applying these datas to excel by using pandas. I have a html code as stated above. I want to take the phone number which is come after

Solution 1:

To print the text 0212 / 897645 you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR, childNodes and strip():

    print(driver.execute_script('return arguments[0].childNodes[5].textContent;', WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.col_5")))).strip())
    
  • Using XPATH, get_attribute() and splitlines():

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[1]/div/div[103]/div[2]"))).get_attribute("innerHTML").splitlines()[4])
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC

References

You can find a couple of relevant detailed discussions in:

Post a Comment for "How To Get Specific Text That Belongs To Div Class"