home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


Subroutine VisitURL fetches one of the documents with site, path, and file name stored in the GotoSite, GotoPath, and GotoFile collections. The routine begins by reading the next site, path, and file name from the Goto collections. It builds the document’s complete URL and checks to see if the URL appears in the BeenThere collection. If so, the document has already been visited so VisitURL is done.

VisitURL then uses the Internet transfer control’s OpenURL method to fetch the document. It passes the returned text to the ExamineDocument subroutine to perform the actual processing of the file.

Private Sub VisitURL()
Dim the_url As String
Dim txt As String
Dim been_there As String

    ‘ Fetch the next URL in the list.
    CurrentSite = GotoSite(NumUrls)
    CurrentPath = GotoPath(NumUrls)
    CurrentFile = GotoFile(NumUrls)
    GotoSite.Remove NumUrls
    GotoPath.Remove NumUrls
    GotoFile.Remove NumUrls
    NumUrls = NumUrls - 1

    ‘ Build the URL.
    the_url = “http://” & CurrentSite & _
        CurrentPath & CurrentFile

    ‘ See if we have already visited it.
    been_there = “”
    On Error Resume Next
    been_there = BeenThere(the_url)
    On Error GoTo 0

    ‘ If we’ve already visited it, quit.
    If been_there <> “” Then Exit Sub

    ‘Add it to the list of visited URLs.
    BeenThere.Add “X”, the_url

    ‘ Try to open the URL.
    On Error Resume Next
    txt = Inet1.OpenURL(the_url)
    If Err.Number <> 0 Then
        Results = Results & “    Error” & _
            Str$(Err.Number) & “ reading ” & _
            the_url & vbCrLf & “    ” & _
            Err.Description & vbCrLf
        Exit Sub
    End If
    On Error GoTo 0

    ‘ Read the document looking for links.
    ExamineDocument the_url, txt
End Sub

Subroutine ExamineDocument searches the returned file for certain key values selected by the user. It begins by checking to see if the document contains the string “Object Not Found.” If OpenURL tries to open a file that does not exist on a Web site, the server will return a valid HTML document that says “Object Not Found.” Normally a Web browser would simply display this document. SiteMapper adds an error message to its result string.

Next, ExamineDocument looks for the names of files with the types selected by the user. When it finds an appropriate file extension, it uses the FindFileType function to find the complete file name within the document. SiteMapper does not actually parse the entire HTML document. It merely searches for appropriate file extensions.

When it finds a file, ExamineDocument adds its name to the Results string. If the file extension is .HTM or .HTML, ExamineDocument also calls the AddURL subroutine. AddURL verifies that the new URL is within the same site and adds it to the list of URLs to visit later.

Private Sub ExamineDocument(the_url As String, txt As String)
Dim i As Integer
Dim pos As Integer
Dim file_name As String

    Results = Results & the_url & “:” & vbCrLf

    ‘ See if it says “Object not found” and
    ‘ not much else.
    If InStr(1, txt, “Object Not Found”, INSENSITIVE) _
        > 0 And Len(txt) < 80 _
    Then
        Results = Results & _
            “    Object Not Found” & vbCrLf
        Exit Sub
    End If

    ‘ Look for each of the selected file types.
    For i = 0 To MAX_FILE_TYPE
        ‘ See if we should visit it.
        If FileTypeCheck(i).Value = vbChecked Then
            ‘ Find the first file of this type.
            pos = 1
            file_name = FindFileType(txt, pos, FileType(i))
            Do While pos > 0
                ‘ Display it.
                Results = Results & “    ” & _
                    file_name & vbCrLf

                ‘ If it’s an HTM or HTML file
                ‘ and it’s in this site,
                ‘ add it to the list of URLs
                ‘ to visit.
                If i = 0 Or i = 1 Then _
                    AddUrl file_name

                ‘ Find the next file of this type.
                file_name = FindFileType(txt, pos, FileType(i))
            Loop
        End If
    Next i

End Sub

Function FindFileType takes as parameters an HTML document, a position at which to start searching the document, and a file’s extension. It searches the document from the indicated point looking for the extension.

If it finds the extension, FindFileType uses the NameStart and NameEnd functions to locate the beginning and end of the file name that contains the extension.

NameStart searches the document backwards from the extension looking for the beginning of the file name. It stops when it reaches a nonprintable character (space, tab), an equals sign, a single or double quote, or an angled bracket. This covers the following situations:

<A HREF=“File.HTM”>...
<A HREF=’File.HTM’>...
<A HREF=File.HTM>...
<A HREF = File.HTM>...

NameEnd searches the document forward from the extension looking for the end of the file name. It stops when it reaches a nonprintable character, an equals sign, a single or double quote, or an angled bracket. It also stops at a number sign so URL markers are not considered part of the file name.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.