Hello All,
I am having trouble being able to capture what I need from an HTML website to extract data for my VBA code.
My code automatically uses a webpage to search the distance between two airports. That part works fine, extracting the actual value of the distance is giving me problems.
The website I am extracting data from is
and my code inputs LAX and ATL as the airports.
The data I want to retrieve is: "1,946.88"
And that could be found where it says "Distance," it should look like this...
Distance: 1,691.43 (NM) / 1,946.88 (MI) / 3,132.53 (KM)
Tips and help are always appreciated!
I am having trouble being able to capture what I need from an HTML website to extract data for my VBA code.
My code automatically uses a webpage to search the distance between two airports. That part works fine, extracting the actual value of the distance is giving me problems.
The website I am extracting data from is
HTML:
http://www.flightmanager.com/content/timedistanceform.aspx
The data I want to retrieve is: "1,946.88"
And that could be found where it says "Distance," it should look like this...
Distance: 1,691.43 (NM) / 1,946.88 (MI) / 3,132.53 (KM)
Code:
Sub parse_distances()
Dim air1, air2 As String
air1 = "ATL"
air2 = "LAX"
' variables are here to check if this code works, DELETE later
Set objIEBrowser = CreateObject("InternetExplorer.Application")
' open Internet Explorer
objIEBrowser.Visible = True
' allows you to see the webpage
objIEBrowser.Navigate2 "http://www.flightmanager.com/content/timedistanceform.aspx"
' opens up the website I will use to find the airport distances
Do While objIEBrowser.Busy
Loop
Do While objIEBrowser.readyState < 4
Loop
' prevents anything else from happening while the site is loading.
Set objPage = objIEBrowser.document
' idk what this is, i'm just trying to follow similar code from an online source
Set Airport1 = objPage.getElementById("ctl00_ContentPlaceHolder1_txtDepartureICAO")
Airport1.Value = air1
Set Airport2 = objPage.getElementById("ctl00_ContentPlaceHolder1_txtArrivalICAO")
Airport2.Value = air2
' Inputs the airport names into the search engine.
Set clickCalcDistButton = objPage.getElementById("ctl00_ContentPlaceHolder1_BtnSubmit")
clickCalcDistButton.Click
Do While objIEBrowser.Busy
Loop
Do While objIEBrowser.readyState < 4
Loop
' prevents anything else from happening while the site is loading.
Dim dist As String
dist = IE.Dcoument.getElementsByClassName("std5")(1).innerText
' THIS IS WHERE I'M HAVING TROUBLE.
End Sub
Tips and help are always appreciated!