I have been learning about scraping data from web pages using Excel and VBA. I cam across a bit of a barrier with one data source so changed to https://www.skyscanner.net/news/airports/heathrow-airport-live-flight-arrivals-and-departures.
The problem I am coming up against is in the table id "flight-status-board-arrivals" there is a and .
I can pull the header data fine but when I try bulling the body data the loop ends. I have tried changing to .children(1) to test and debugging using length which returns 0. This indicates there is nothing in the object but I cant understand why. I hope I have covered everything here and any help would be possible. Also, I know this could be achieved using another language however as I am learning VBA I thought it best to learn using VBa before delving into a new language.`
Sub GrabWebData()
Dim ie As InternetExplorer 'refer to the running copy of internet explorer
Dim html As HTMLDocument 'refer to the HTML document returned
Dim ele As Object
Dim y As Integer
Dim fSht As Worksheet
Set fSht = Sheets("Sheet1")
Set ie = New InternetExplorer
ie.Visible = False
ie.navigate "https://www.skyscanner.net/news/airports/heathrow-airport-live-flight-arrivals-and-departures"
'wait until IE is done loading page
Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Loading Flight Times"
DoEvents
Loop
y = 1
Debug.Print ie.document.getElementById("flight-status-board-arrivals").Children(1) _
.getElementsByTagName("td").Length
For Each ele In ie.document.getElementById("flight-status-board- arrivals").Children(1) _
.getElementsByTagName("tr")
Debug.Print ele.textContent
fSht.Range("A" & y).Value = ele.Children(0).textContent
'On Error GoTo skip1:
fSht.Range("B" & y).Value = ele.Children(1).textContent
'On Error GoTo skip1:
fSht.Range("C" & y).Value = ele.Children(2).textContent
'On Error GoTo skip1:
fSht.Range("D" & y).Value = ele.Children(3).textContent
'On Error GoTo skip1:
fSht.Range("E" & y).Value = ele.Children(4).textContent
'On Error GoTo skip1:
fSht.Cells.WrapText = False
fSht.Rows.AutoFit
fSht.Columns.AutoFit
'skip1:
y = y + 1
Next
'Rows(2).Select
'Selection.Delete shift:=xlUp
End Sub`