Problem getting multiple items from a web page.

I wrote a script in python in combination with selenium to parse some elements from a web page. Anyway, I can't get it to work. The elements that I follow it (maybe) are within the iframe . I tried switching it, but this has no effect. I still get nothing except a TimeoutException when it hits the line where I tried to switch the iframe . How can I make it work. Thank you in advance:

Here is the link to the web page: URL

 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC url = "replace_with_above_url" driver = webdriver.Chrome() driver.get(url) wait = WebDriverWait(driver, 10) wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "tradingview_fe623"))) for item in wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".quick .apply-common-tooltip"))): print(item.text) driver.quit() 

Elements in which the elements that I execute them:

 <div class="quick"> <span class="apply-common-tooltip">5</span> <span class="apply-common-tooltip">1h</span> <span class="apply-common-tooltip selected">1D</span> <span class="apply-common-tooltip">1M</span> <span class="apply-common-tooltip">1D</span> </div> 

This is the result I expect to have (it works locally when I try to get them using css selectors):

 5 1h 1D 1M 1D 

Here's what it looks like on the Internet:

enter image description here

+5
source share
1 answer

Necessary nodes located inside 2 nested iframes, so you need to switch to them one at a time. Note that the id / name second is dynamically generated. Just try replacing

 wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "tradingview_fe623"))) 

with

 wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, ".abs"))) wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[id^='tradingview_']"))) 
+4
source

Source: https://habr.com/ru/post/1274169/


All Articles