On this website (https://www.tradingview.com/symbols/NASDAQ-TSLA/financials-income-statement/), there is a table with clickable arrows on some of the rows. I've been trying to use Python Selenium and 'driver.find_elements_by_xpath'
to find the arrows (within the table only) and continue clicking on the arrows until all of the rows within table have been fully expanded before scraping, but have been struggling.
The xpath
to some of these arrows shown below, but there are some hidden arrows, which will only become visible to click once the first arrow is clicked
//span[@class='arrow-jKD0Exn-']//*[name()='svg']
CodePudding user response:
The arrows have class name jKD0Exn
use that element to click then search for the next one
Example for CSS Selector
div.container-jKD0Exn-:nth-child(2) > div:nth-child(2) > span:nth-child(2)
CodePudding user response:
driver.maximize_window()
wait=WebDriverWait(driver,10)
driver.get('https://www.tradingview.com/symbols/NASDAQ-TSLA/financials-income-statement/')
wait.until(EC.element_to_be_clickable((By.XPATH,"//span[.='Accept']"))).click()
while True:
try:
wait.until(EC.element_to_be_clickable((By.XPATH,"//div[contains(@class,'titleWrap')]//span[contains(@class,'arrow') and not(contains(@class,'opened'))]//*[name()='svg']"))).click()
time.sleep(1)
except:
break
Open all the svgs that have that class and nested openings I think you want. It breaks when there are no more of that type.
Import:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time