Any automation software to pull the data from fundamental explorer?

Discussion in 'Interactive Brokers' started by emk662, Feb 11, 2025.

  1. emk662

    emk662

    I like to use in Excel, so VBA will be appreciated.

     
    #11     Feb 12, 2025
  2. Peter8519

    Peter8519

    Here is the VBA script current year average earning estimate. Using python script will be much faster. But I don't use it. So, I cannot help.

    Sub Finance_Stats()

    Dim i As Integer
    Dim my_doc As Object
    Dim my_url As String
    Const yahoo_url = "https://finance.yahoo.com/quote/XXXXX/financials/"
    Const yahoo_url2 = "https://finance.yahoo.com/quote/XXXXX/analysis/"

    Dim XMLpage As New MSXML2.XMLHTTP60
    Dim HTMLdoc As New MSHTML.htmlDocument

    ThisWorkbook.Sheets("Sheet1").Columns("B:E").ClearContents
    ThisWorkbook.Sheets("Sheet1").Cells(1, 2) = "Total Revenue"
    ThisWorkbook.Sheets("Sheet1").Cells(1, 3) = "Diluted EPS(TTM)"
    ThisWorkbook.Sheets("Sheet1").Cells(1, 4) = "Avg earning Est"
    i = 2

    While ThisWorkbook.Sheets("Sheet1").Cells(i, 1) <> ""

    'Update URL with ticker symbol for Financials
    my_url = Replace(yahoo_url, "XXXXX", ThisWorkbook.Sheets("Sheet1").Cells(i, 1))

    XMLpage.Open "GET", my_url, False
    XMLpage.send

    'Wait till page fully loaded
    While XMLpage.Status <> 200
    Application.Wait (Now + TimeValue("0:00:01"))
    Wend

    HTMLdoc.body.innerHTML = XMLpage.responseText
    'Right click the number of interest in your browser and select Inspect. It will bring you to the search HTML.
    'If Yahoo Finance changes the clase name, you need to do this step again and update the class name.
    Set my_doc = HTMLdoc.getElementsByClassName("tableBody yf-9ft13")
    ThisWorkbook.Sheets("Sheet1").Cells(i, 2) = my_doc(0).ChildNodes.Item(1).ChildNodes.Item(3).innerText
    ThisWorkbook.Sheets("Sheet1").Cells(i, 3) = my_doc(0).ChildNodes.Item(25).ChildNodes.Item(2).innerText

    'Update URL with ticker symbol for Analysis
    my_url = Replace(yahoo_url2, "XXXXX", ThisWorkbook.Sheets("Sheet1").Cells(i, 1))

    XMLpage.Open "GET", my_url, False
    XMLpage.send

    'Wait till page fully loaded
    While XMLpage.Status <> 200
    Application.Wait (Now + TimeValue("0:00:01"))
    Wend

    HTMLdoc.body.innerHTML = XMLpage.responseText
    'Right click the number of interest in your browser and select Inspect. It will bring you to the search HTML.
    'In this case, use tag name. The number of interest is in the current object tbody, 2nd row and 4th column
    'Need try error method on the index in order to get the right number.
    'Can also use getElementsByTagName method.
    Set my_doc = HTMLdoc.getElementsByTagName("tbody")
    'ThisWorkbook.Sheets("Sheet1").Cells(i, 4) = my_doc(0).ChildNodes.Item(1).ChildNodes.Item(4).innerText
    ThisWorkbook.Sheets("Sheet1").Cells(i, 4) = my_doc(0).getElementsByTagName("tr")(1).getElementsByTagName("td")(3).innerText
    i = i + 1
    Wend

    End Sub
     
    #12     Feb 12, 2025
  3. emk662

    emk662

    It works. Thank you so much.
     
    #13     Feb 12, 2025
  4. emk662

    emk662

    Hello, I need help again to get Analyst Price Targets-> Average number from Yahoo Finance. For example, https://finance.yahoo.com/quote/NFLX/analysis/ the result should be 1068.19. Can you help me on the VBA script? Suppose I already get the response text. Many thanks.
     
    #14     Apr 18, 2025