Home > other >  How to use XPath to scrape javascript website values
How to use XPath to scrape javascript website values

Time:01-11

I'm trying to scrape (in python) the savings interest rate from enter image description here

You can also get elements by containing text APY:

'//span[contains(., "APY")]'

enter image description here But this selector looks for all span elements in the DOM that contain word APY.

CodePudding user response:

If you find unique id, it is recommended to be priority, like this :find_element(By.ID,'hysa-apy-2') like @John Gordon comment.

But sometimes when the element found, the text not yet load.

Use xpath with add this logic and text()!=""

element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//span[@id="hysa-apy-2" and text()!=""]')))

Following import:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
  • Related