Hello, I like to get financial data such as total revenue from TWS Fundamental explorer. It used to have an API function that can work, but now that function is deprecated. I can manually open the fundamental explorer to get the data, but was wondering if it can be done using a software or a smart way, since I have a long list of stocks. Thanks.
Have you tried the "Wall Street Horizon" methods? https://www.interactivebrokers.com/campus/ibkr-api-page/twsapi-doc/#wsh You will need to activate your subscription to the service first.
You can download the total revenue data from yahoo finance using Excel VBA. Here is the Excel VBA script. Sub Scrape_Yahoo_Finance() Dim i As Integer Dim my_doc As Object Dim my_url As String Const yahoo_url = "https://finance.yahoo.com/quote/XXXXX/financials/" Dim XMLpage As New MSXML2.XMLHTTP60 Dim HTMLdoc As New MSHTML.htmlDocument ThisWorkbook.Sheets("Sheet1").Columns("B:B").Clear ThisWorkbook.Sheets("Sheet1").Cells(1, 2) = "Total Revenue" i = 2 While ThisWorkbook.Sheets("Sheet1").Cells(i, 1) <> "" my_url = Replace(yahoo_url, "XXXXX", ThisWorkbook.Sheets("Sheet1").Cells(i, 1)) XMLpage.Open "GET", my_url, False XMLpage.send HTMLdoc.body.innerHTML = XMLpage.responseText my_doc = HTMLdoc.getElementsByClassName("tableBody yf-9ft13") ThisWorkbook.Sheets("Sheet1").Cells(i, 2) = my_doc.childNodes.Item(1).childNodes.Item(3).innerText i = i + 1 Wend End Sub In the Excel VBA editor, go to Tools -> Reference and check the following. In the Excel Sheet1, row 1,col1 = Ticker. From row2, col1 onwards is your ticker symbol.
You might want to look into web scraping tools like Selenium or BeautifulSoup, but be sure to check Interactive Brokers' terms of service. Another option is third-party financial data APIs like Alpha Vantage, Yahoo Finance, or Finnhub, which might provide the data you need without manual work.
I rerun the Excel macro and it has error. Here is the fully debugged script. 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/" Dim XMLpage As New MSXML2.XMLHTTP60 Dim HTMLdoc As New MSHTML.htmlDocument ThisWorkbook.Sheets("Sheet1").Columns("B:C").Clear ThisWorkbook.Sheets("Sheet1").Cells(1, 2) = "Total Revenue" ThisWorkbook.Sheets("Sheet1").Cells(1, 3) = "Diluted EPS(TTM)" i = 2 While ThisWorkbook.Sheets("Sheet1").Cells(i, 1) <> "" 'Update URL with ticker symbol 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 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 i = i + 1 Wend End Sub
Hello, thanks so much. Can you also show how to get the average earnings estimate (under analysis) for the current year?