Link to home
Start Free TrialLog in
Avatar of scbdpm
scbdpmFlag for United States of America

asked on

Getting html from a web page

I am posting this here as I want to run this in VB.... not quite sure how to pose the question so bear with me....

I am writing an app that will be used for flight planning for pilots.
There is a printed book called the Airport Facility Directory (AFD) which has information about airports.
It has become available electronically at: http://naco.faa.gov/afd.asp?cycle=afd_14FEB2008&eff=02-14-2008&end=04-10-2008#

So, how to use this webpage. You either click on the state where the airport is located that you want the information on. Or, you use the drop-down. Then, with the second drop-down populated, you choose the airport ID.
When you click Search, you will see the links to the pages from the electronic AFD below.

I want to be able to download those pdf pages but cant seem to figure out how. The link provided to the pdf page is not 'visible' when you view source in IE and therefore not a link I can grab.

Basically, i would like my app to go out with the airport identifier (three letter Ident) and pull the link to the pdf and then download it.....

HELP! If this is confusing, please let me know...
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

http://avn.faa.gov/afd.asp?cycle=afd_14FEB2008&eff=02-14-2008&end=04-10-2008  linked from faa search but seems to be offline.

The code is almost certainly a form submission and should be able to be determined from the HTML source.

Avatar of scbdpm

ASKER

the links appear to be working now.

Can you provide more guidance?

What you mention is true and I assumed that too but not sure how to proceed.
You will find that the "Rear" files are huge and take a long time to download.  Some of them are over 50 MB, and the site doesn't seem to provide very fast downloads.  So prepare to take a lot of time to download the files... The program may appear hung.


The URLs are region based like this.  I've mapped these to the state level based on the javascript in the page.

URLFront = "http://naco.faa.gov/pdfs/" & strRegion & "_front_14FEB2008.pdf"
URLRear = "http://naco.faa.gov/pdfs/" & strRegion & "_rear_14FEB2008.pdf"

Create a new form, add a listbox and a button.  Then paste in this code.
Option Explicit
Private mcolRegions As Collection
 
Private Declare Function URLDownloadToFile Lib "urlmon" _
   Alias "URLDownloadToFileA" _
  (ByVal pCaller As Long, _
   ByVal szURL As String, _
   ByVal szFileName As String, _
   ByVal dwReserved As Long, _
   ByVal lpfnCB As Long) As Long
   
 
Private Sub Command1_Click()
    Dim strState As String, strRegion As String
    If List1.ListIndex = -1 Then Exit Sub
    
    strState = List1.List(List1.ListIndex)
    strRegion = mcolRegions.Item(strState)
    DownloadFiles strRegion
    
    
End Sub
 
Public Function fParseBetween(ByVal strChk As String, ByVal strFirst As String, ByVal strLast As String, Optional lngStart As Long = 1) As String
    Dim lngPos As Long, lngLen As Long
    
    lngPos = InStr(lngStart, strChk, strFirst, vbTextCompare) + Len(strFirst)
    lngLen = InStr(lngPos, strChk, strLast, vbTextCompare) - lngPos
    
    If lngPos > 0 And lngLen > 0 Then
        fParseBetween = Mid$(strChk, lngPos, lngLen)
        If Len(fParseBetween) > 0 Then
            lngStart = lngStart + Len(fParseBetween)
        End If
    End If
    
End Function
 
 
 
Private Sub DownloadFiles(strRegion As String)
   
    Dim URLFront As String
    Dim URLRear As String
    Dim FileFront As String
    Dim FileRear As String
    URLFront = "http://naco.faa.gov/pdfs/" & strRegion & "_front_14FEB2008.pdf"
    URLRear = "http://naco.faa.gov/pdfs/" & strRegion & "_rear_14FEB2008.pdf"
    FileFront = App.Path & "\" & strRegion & "_front_14FEB2008.pdf"
    FileRear = App.Path & "\" & strRegion & "_rear_14FEB2008.pdf"
    DownloadFile URLFront, FileFront
    DownloadFile URLRear, FileRear
End Sub
 
Public Sub DownloadFile(strURL As String, strFilename As String)
    If Not (URLDownloadToFile(0, strURL, strFilename, &H10, 0) = 0) Then
        MsgBox "Could not download " & strURL
    End If
End Sub
 
 
 
Private Sub Form_Load()
    Set mcolRegions = New Collection
 
    mcolRegions.Add "se", "Alabama"
    List1.AddItem "Alabama"
    mcolRegions.Add "al", "Alaska"
    List1.AddItem "Alaska"
    mcolRegions.Add "pac", "American Samoa"
    List1.AddItem "American Samoa"
    mcolRegions.Add "sw", "Arizona"
    List1.AddItem "Arizona"
    mcolRegions.Add "sc", "Arkansas"
    List1.AddItem "Arkansas"
    mcolRegions.Add "sw", "California"
    List1.AddItem "California"
    mcolRegions.Add "sw", "Colorado"
    List1.AddItem "Colorado"
    mcolRegions.Add "ne", "Connecticut"
    List1.AddItem "Connecticut"
    mcolRegions.Add "ne", "Delaware"
    List1.AddItem "Delaware"
    mcolRegions.Add "ne", "District Of Columbia"
    List1.AddItem "District Of Columbia"
    mcolRegions.Add "pac", "Federated States Of Micronesia"
    List1.AddItem "Federated States Of Micronesia"
    mcolRegions.Add "se", "Florida"
    List1.AddItem "Florida"
    mcolRegions.Add "se", "Georgia"
    List1.AddItem "Georgia"
    mcolRegions.Add "pac", "Guam"
    List1.AddItem "Guam"
    mcolRegions.Add "pac", "Hawaii"
    List1.AddItem "Hawaii"
    mcolRegions.Add "nw", "Idaho"
    List1.AddItem "Idaho"
    mcolRegions.Add "ec", "Illinois"
    List1.AddItem "Illinois"
    mcolRegions.Add "ec", "Indiana"
    List1.AddItem "Indiana"
    mcolRegions.Add "nc", "Iowa"
    List1.AddItem "Iowa"
    mcolRegions.Add "nc", "Kansas"
    List1.AddItem "Kansas"
    mcolRegions.Add "se", "Kentucky"
    List1.AddItem "Kentucky"
    mcolRegions.Add "pac", "Kiribati"
    List1.AddItem "Kiribati"
    mcolRegions.Add "pac", "Kure Island"
    List1.AddItem "Kure Island"
    mcolRegions.Add "sc", "Louisiana"
    List1.AddItem "Louisiana"
    mcolRegions.Add "ne", "Maine"
    List1.AddItem "Maine"
    mcolRegions.Add "pac", "Marshall Islands"
    List1.AddItem "Marshall Islands"
    mcolRegions.Add "ne", "Maryland"
    List1.AddItem "Maryland"
    mcolRegions.Add "ne", "Massachusetts"
    List1.AddItem "Massachusetts"
    mcolRegions.Add "ec", "Michigan"
    List1.AddItem "Michigan"
    mcolRegions.Add "nc", "Minnesota"
    List1.AddItem "Minnesota"
    mcolRegions.Add "se", "Mississippi"
    List1.AddItem "Mississippi"
    mcolRegions.Add "nc", "Missouri"
    List1.AddItem "Missouri"
    mcolRegions.Add "nw", "Montana"
    List1.AddItem "Montana"
    mcolRegions.Add "nc", "Nebraska"
    List1.AddItem "Nebraska"
    mcolRegions.Add "sw", "Nevada"
    List1.AddItem "Nevada"
    mcolRegions.Add "ne", "New Hampshire"
    List1.AddItem "New Hampshire"
    mcolRegions.Add "ne", "New Jersey"
    List1.AddItem "New Jersey"
    mcolRegions.Add "sc", "New Mexico"
    List1.AddItem "New Mexico"
    mcolRegions.Add "ne", "New York"
    List1.AddItem "New York"
    mcolRegions.Add "se", "North Carolina"
    List1.AddItem "North Carolina"
    mcolRegions.Add "nc", "North Dakota"
    List1.AddItem "North Dakota"
    mcolRegions.Add "ec", "Ohio"
    List1.AddItem "Ohio"
    mcolRegions.Add "sc", "Oklahoma"
    List1.AddItem "Oklahoma"
    mcolRegions.Add "nw", "Oregon"
    List1.AddItem "Oregon"
    mcolRegions.Add "ne", "Pennsylvania"
    List1.AddItem "Pennsylvania"
    mcolRegions.Add "se", "Puerto Rico"
    List1.AddItem "Puerto Rico"
    mcolRegions.Add "ne", "Rhode Island"
    List1.AddItem "Rhode Island"
    mcolRegions.Add "se", "South Carolina"
    List1.AddItem "South Carolina"
    mcolRegions.Add "nc", "South Dakota"
    List1.AddItem "South Dakota"
    mcolRegions.Add "se", "Tennessee"
    List1.AddItem "Tennessee"
    mcolRegions.Add "sc", "Texas"
    List1.AddItem "Texas"
    mcolRegions.Add "sw", "Utah"
    List1.AddItem "Utah"
    mcolRegions.Add "ne", "Vermont"
    List1.AddItem "Vermont"
    mcolRegions.Add "se", "Virgin Islands"
    List1.AddItem "Virgin Islands"
    mcolRegions.Add "ne", "Virginia"
    List1.AddItem "Virginia"
    mcolRegions.Add "nw", "Washington"
    List1.AddItem "Washington"
    mcolRegions.Add "ne", "West Virginia"
    List1.AddItem "West Virginia"
    mcolRegions.Add "ec", "Wisconsin"
    List1.AddItem "Wisconsin"
    mcolRegions.Add "nw", "Wyoming"
    List1.AddItem "Wyoming"
 
    
       
End Sub

Open in new window

Avatar of scbdpm

ASKER

PaulHews:

thanks for the post. However, that isn't quite what I was looking for.... what you are downloding there is just the front and rear portions of the AFD (airport facility directory) for the region that the state you select is in.

What I want is the individual page for the airport you select.

Let me give you a scenerio:

on the page: http://naco.faa.gov/afd.asp?cycle=afd_14FEB2008&eff=02-14-2008&end=04-10-2008 you select Connecticut from the 'Select a State' drop down.
the second drop down 'Airport ID' refreshes and gives you all the airports in Connecticut.
I then chose BDL and you would then click search.

Towards the bottom of the page you will see 'Airport/NAVAID Results' show up with 'Airport Name', etc and a link to the PDF for 'BRADLEY INTL ' called: "View PDF"

this is the link I am trying to get......
That's still region based, not airport based.  For BDL, the region code is ne and the link there is:

http://naco.faa.gov/pdfs/ne_11_14FEB2008.pdf

Private Sub DownloadFiles(strRegion As String)
    Dim URL As String
    Dim FileName As String
    
    URL = "http://naco.faa.gov/pdfs/" & strRegion & "_11_14FEB2008.pdf"
    FileName = App.Path & "\" & strRegion & "_11_14FEB2008.pdf"
    DownloadFile URL, FileName
    
End Sub

Open in new window

Avatar of scbdpm

ASKER

maybe I'm missing what you are saying but this isnt' what I'm looking for....


it is airport based because what happens is that each time this directory is printed, it could have more or it could have less pages.... so the region may still be ne but the page for BDL may not be 11_14.....

what I want to do is go out and query this page: http://naco.faa.gov/afd.asp?cycle=afd_14FEB2008&eff=02-14-2008&end=04-10-2008  (or whatever it will be the next cycle) with an airport code such as BDL.

I want to be able to determine from that the link I need is http://naco.faa.gov/pdfs/ne_11_14FEB2008.pdf
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scbdpm

ASKER

That is EXACTLY what I was looking for!!!!

thanks for your persistence!

A+ on this one!
Avatar of scbdpm

ASKER

PaulHews:

if you are monitoring this question still, can you respond......

I need to post another question as a follow-up. I'd like to see you respond to get the points.

the xml file has changed....

I'm still here.  If I have the time I'll check out your new question, but I only see one that you deleted.
Avatar of scbdpm

ASKER

yes, actually I trolled a bit more and found my answer, but thanks for offer to help.

I may still need assitance...
No problem.