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


These rules for finding file names are not perfect, but they work in the majority of cases. For instance, the HTML code <A HREF=“File Name With Spaces.HTM”> references a file name that is valid in some operating systems, including Windows 95 and Windows NT. File names that contain spaces are not guaranteed to transmit safely across the Web, however, so they are rare in Web pages.

Private Function FindFileType(txt As String, pos As Integer, _
    ext As String) As String
Dim pos1 As Integer
Dim pos2 As Integer
Dim pos3 As Integer

    ‘ Find the extension.
    pos2 = InStr(pos, txt, ext, INSENSITIVE)
    If pos2 = 0 Then
        pos = 0
        FindFileType = “”
        Exit Function
    End If

    ‘ Find the beginning of the file name.
    pos1 = NameStart(txt, pos2 - 1)

    ‘ Find the end of the file name.
    pos3 = NameEnd(txt, pos2 + Len(ext))

    ‘ Get the resulting file name.
    FindFileType = Mid$(txt, pos1, pos3 - pos1 + 1)

    ‘ Move pos after the name.
    pos = pos3 + 1
End Function

Private Function NameStart(txt As String, pos2 As Integer) As Integer
Dim i As Integer
Dim ch As String

    ‘ Look for a stopping character.
    For i = pos2 To 1 Step -1
        ch = Mid$(txt, i, 1)

        If ch <= “ ” Or ch > “~” Or _
            ch = “”“” Or ch = “‘” Or _
            ch = “<” Or ch = “>” Or ch = “=” _
            Then Exit For

        If ch <= “ ” Or ch > “~” Or _
            ch = “”“” Or ch = “‘” _
            Then Exit For
    Next i
    NameStart = i + 1
End Function

Private Function NameEnd(txt As String, pos2 As Integer) As Integer
Dim txt_len As Integer
Dim i As Integer
Dim ch As String

    txt_len = Len(txt)

    ‘ Look for a stopping character.
    For i = pos2 To txt_len
        ch = Mid$(txt, i, 1)
        If ch <= “ ” Or ch > “~” Or _
            ch = “”“” Or ch = “‘” Or _
            ch = “<” Or ch = “>” Or ch = “#” _
            Then Exit For
    Next i
    NameEnd = i - 1
End Function

Subroutine AddURL is the last major piece of SiteMapper. It begins by using ParseURL to separate the URL’s pieces. It compares the URL’s site to the variable CurrentSite to ensure that the URL is within the current site.

AddURL then uses CompleteURL to convert a partial URL into an absolute URL. It adds the completed site, path, and file names to the GotoSite, GotoPath, and GotoFile collections. Later the VisitURL subroutine will retrieve these values and visit the document if it has not already been visited.

Private Sub AddUrl(ByVal the_url As String)
Dim the_protocol As String
Dim the_site As String
Dim the_path As String
Dim the_file As String

    ‘ Parse the URL.
    ParseURL the_url, the_protocol, _
        the_site, the_path, the_file

    ‘ Make sure it’s in the same site.
    If the_site <> “” And _
        the_site <> CurrentSite Then Exit Sub

    ‘ Complete the URL to give it a site and
    ‘ absolute path.
    CompleteURL the_site, the_path

    ‘ Add the URL components to the list.
    GotoSite.Add the_site
    GotoPath.Add the_path
    GotoFile.Add the_file
    NumUrls = NumUrls + 1
End Sub

Modifying SiteMapper

SiteMapper searches documents at a Web site that are related to an initial URL. It presents a list of the files referenced in those documents. In addition to describing the layout of the site, this provides useful Web debugging information. In one test on my home page, SiteMapper discovered that one of the connected documents referred to the file AnoutRod.HTM. This was a typographical error—the file’s name should have been AboutRod.HTM. When SiteMapper tried to visit the nonexistent AnoutRod.HTM, it presented an error message indicating that the file did not exist. This made it easy to find and correct the problem.

SiteMapper could be enhanced to provide even more file validation. For example, it could attempt to open each of the .GIF, .JPG, and .JPEG files it encountered. If a file could not be opened, SiteMapper would present an error message.

SiteMapper currently searches documents for file name extensions. It could be easily modified to search for keywords as well. SiteMapper could traverse Web documents and present a list of the documents that contained certain words or phrases.

The program could also traverse documents in more than one Web site. In that case, it would need some method for deciding which sites to visit. Without some direction the program would attempt to traverse the entire World Wide Web. Assuming the computer had enough disk space and memory, such an unrestricted search would take an extremely long time.

Instead of running unchecked for weeks, the program could ask the user for permission to visit each new site it encountered. Alternatively, it could keep track of the number of intermediate sites between the starting URL and new documents. The program would not visit sites where the number of intermediate sites exceeded some limit.

Some search engines use an unrestricted Web search to gather data. These Web crawlers, spiders, and worms traverse sites all over the Web, looking for interesting information and adding it to their databases. Users can later search the databases for keywords to obtain a list of the URLs that might be interesting.

Summary

SiteMapper only hints at the possibilities available to an automated Web client program. Such a program can be used to map and debug a Web site, list all of the files available at a site, or search for specific keywords and phrases. The program can even use artificial intelligence methods to identify pages containing information related to certain topics of interest. Using search techniques, it can venture out onto the larger Web and examine many sites to achieve its goal.


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.