Hi,
I am trying to retrieve data from a table of a website, but I am stuck getting the correct tagname.
Website :
Here's what I wrote so far :
and this is the website details :
Exact info I need for each tr.
Also, the table on the website, has the option to select 100 items to display, how can I select that in my macro ?
Any help is well appreciated !
Thanks
I am trying to retrieve data from a table of a website, but I am stuck getting the correct tagname.
Website :
What date does Apple's (AAPL) report Earnings - Earnings Calendar & Announcement
Learn more about Apple's (AAPL) upcoming earnings announcement. Get Earnings Calendar and Data from Zacks.com
www.zacks.com
Here's what I wrote so far :
VBA Code:
Public Sub Zacks()
Dim html As MSHTML.HTMLDocument, hTable As Object, ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")
Set html = New MSHTML.HTMLDocument '< VBE > Tools > References > Microsoft Scripting Runtime
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://www.zacks.com/stock/research/AAPL/earnings-announcements", False
.send
html.body.innerHTML = .responseText
End With
Set hTable = html.querySelector("earnings_annoucements_earnings_table")
Dim td As Object, tr As Object, th As Object, r As Long, c As Long
For Each tr In hTable.getElementsByTagName("tr")
r = r + 1: c = 1
For Each th In tr.getElementsByTagName("th")
ws.Cells(r, c) = th.innerText
c = c + 1
Next
For Each td In tr.getElementsByTagName("td")
ws.Cells(r, c) = td.innerText
c = c + 1
Next
Next
End Sub
and this is the website details :
Exact info I need for each tr.
Also, the table on the website, has the option to select 100 items to display, how can I select that in my macro ?
Any help is well appreciated !
Thanks
Last edited: