I would like to get table to Worksheet in Excel after search has been performed. My code is accessing web page, inputs values from Worksheet but I am not able to extract table to Excel. Any ideas what is wrong in my current code and how to get it work?
Sub GetFerryRatesAutomatic()
Dim appIE As Object
Dim tbl, trs, tr, tds, td, r, c
Set appIE = CreateObject("internetexplorer.application")
With appIE
.Navigate "https://laevapiletid.ee/setlang/eng"
.Visible = True
End With
Do While appIE.Busy
DoEvents
Loop
appIE.Document.getElementsByName("trip_outbound")(0).Value = "HEL-TAL"
appIE.Document.getElementsByName("trip_inbound")(0).Value = "TAL-HEL"
appIE.Document.getElementsByName("vehicle")(0).Value = "CAR1"
appIE.Document.getElementsByName("passenger[ADULT]")(0).Value = ThisWorkbook.Sheets("Other Data").Range("F18")
appIE.Document.getElementsByName("trip_inbound_date")(0).Value = ThisWorkbook.Sheets("Other Data").Range("F20")
appIE.Document.getElementsByName("trip_outbound_date")(0).Value = ThisWorkbook.Sheets("Other Data").Range("F19")
appIE.Document.getElementsByClassName("btn btn-lg btn-block btn-primary")(0).Click
'This part is for extracting table
Set tbl = appIE.Document.getElementsByTagName("travelSelect")(5)
Set trs = tbl.getElementsByTagName("travels_tableOutbound")
For r = 0 To trs.Length - 1
Set tds = trs(r).getElementsByTagName("td")
If tds.Length = 0 Then Set tds = trs(r).getElementsByTagName("th")
For c = 0 To tds.Length - 1
ActiveSheet.Range("A1").Offset(r, c).Value = tds(c).innerText
Next c
Next r
'appIE.Quit
Set appIE = Nothing
End Sub
Here is HTML of web page and table I would like to have on my worksheet: