I am trying to extract data from HTML tables like the one at the site in the code below and am not sure what I'm doing wrong as I am not familiar with HTML classes, elements, etc. I found some code that reportedly worked, however I did not have access to visit the site provided so could not fully test. Code I am trying to run is below, any help would be much appreciated.
Option Explicit
Sub test()
Dim oDom As Object: Set oDom = CreateObject("htmlFile")
Dim x As Long, y As Long
Dim oRow As Object, oCell As Object
Dim data
y = 1: x = 1
With CreateObject("msxml2.xmlhttp")
.Open "GET", "https://www.nascar.com/results/racecenter/2021/nascar-cup-series/cook-out-southern-500", False
.send
oDom.body.innerHTML = .responseText
End With
With oDom.getElementsByTagName("race-center-entry-list race-center-lineup")(0)
ReDim data(1 To .Rows.Length, 1 To .Rows(1).Cells.Length)
For Each oRow In .Rows
For Each oCell In oRow.Cells
data(x, y) = oCell.innerText
y = y + 1
Next oCell
y = 1
x = x + 1
Next oRow
End With
Sheets(1).Cells(1, 1).Resize(UBound(data), UBound(data, 2)).Value = data
End Sub
getElementsByClassNameinsteadhttps://cf.nascar.com/cacher/2021/1/5078/weekend-feed.json- you will need a json parser to handle the response. The data you want is dynamically retrieved by the webpage and not present in the response you are currently getting.