I'm a newbie at VBA and was trying to extract flight prices from Expedia (SG to Bangkok) for some practice. My code is not working out too well, unfortunately. It only returned one price (which I have no idea where it came from). Would really appreciate it if anyone could help me out. Thank you!
Sub ExtractRaw()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True .navigate "https://www.expedia.com.sg/Flights-Search?rfrr=TG.LP.SrchWzd.Flight&langid=2057&trip=OneWay&leg1=from:Singapore,%20Singapore%20(SIN-Changi),to:Bangkok,%20Thailand%20(BKK-Suvarnabhumi%20Intl.),departure:" & DateAdd("d", 1, Date) & "TANYT&passengers=children:0,adults:1,seniors:0,infantinlap:Y&options=cabinclass:economy,sortby:price,carrier:&mode=search&paandi=true"
Do While ie.Busy
DoEvents
Loop
Dim doc As HTMLDocument
Set doc = ie.document
While ie.readyState <> 4
Wend
On Error Resume Next
Dim i As Integer For i = 0 To 200
Range("A1").Value = ie.document.getElementById("flight-listing-container").getElementsByClassName("dollars price-emphasis")(i).innerText
Next i
ie.Quit
Application.EnableEvents = True
End With
End Sub