I am trying to scrape the country information from the website below,
https://www.morningstar.com/etfs/xnas/vnqi/portfolio
which entails clicking the 'Country' selection in the Exposure section, then moving through the 1, 2,3, etc. pages using the arrows at the bottom of the section. Nothing I have tried seems to work. Is there a way to do it using selenium in Python?
Many thanks!
Here is the code I used:
urlpage = 'https://www.morningstar.com/etfs/xnas/vnqi/portfolio'
driver = webdriver.Chrome(options=options, executable_path='D:\Python\Python38\chromedriver.exe')
driver.get(urlpage)
elements=WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH, "//a[text()='Country']")))
for elem in elements:
elem.click()
and this is the error message:
TimeoutException
Traceback (most recent call last)
<ipython-input-3-bf16ea3f65c0> in <module>
23 driver = webdriver.Chrome(options=options, executable_path='D:\Python\Python38\chromedriver.exe')
24 driver.get(urlpage)
---> 25 elements=WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH, "//a[text()='Country']")))
26 for elem in elements:
27 elem.click()
D:\Anaconda\lib\site-packages\selenium\webdriver\support\wait.py in until(self, method, message)
78 if time.time() > end_time:
79 break
---> 80 raise TimeoutException(message, screen, stacktrace)
81
82 def until_not(self, method, message=''):
TimeoutException: Message:
Sorry, not sure how to format the error message better. Thanks again.
It seems you didn't check what you really have in
HTML. So you didn't do the most important thing.There is NO
<a>with textCountryon this page.There is
<input>withvalue="Country"This code works for me
Result