[Python] How to get data from 'Balance Sheet' on 'Google finace' with Python and Selenium?

Discussão em 'Python' iniciado por Stack, Maio 18, 2025.

  1. Stack

    Stack Membro Participativo

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.chrome.options import Options
    from bs4 import BeautifulSoup


    driver = webdriver.Chrome()

    url='https://www.google.com/finance'

    driver.get(url)

    input_element = driver.find_elements(By.CLASS_NAME, 'Ax4B8.ZAGvjd')[1]
    input_element.send_keys('nvda stock')
    input_element.send_keys(Keys.ENTER)
    time.sleep(3)

    soup = BeautifulSoup(driver.page_source, 'html.parser')
    soup.find_all('td', class_='QXDnM')[10]


    From above code, I could know the 'Total equity' of Jan 2025 in 'Balance Sheet'.

    However, I cannot know how to get the data from Jan 2024 to Oct 2024.

    I can move from Jan 2024 to Oct 2024 and get data in the dataset of 'Income Statement' by below code.

    driver.find_element(By.XPATH, '//*[@id="option-2"]/span').click()
    soup = BeautifulSoup(driver.page_source, 'html.parser')
    soup.find_all('td', class_='QXDnM')[5] # EBITDA


    However, I still couldn't know how to get dataset of 'Balance Sheet'.

    The problem is date click code is same for 'Income Statement' and 'Balance Sheet' as below.

    driver.find_element(By.XPATH, '//*[@id="option-2"]/span').click()

    Continue reading...

Compartilhe esta Página