Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleRead the links on a Web page
KeywordsWeb, URL, link, WebBrowser
CategoriesControls
 
Use the WebBrowser control's Navigate method to load a Web page. When the document finishes loading, loop through the WebBrowser1.Document.links collection to examine the link objects.

Note that this program sets a reference to the Microsoft HTML Object Library.

 
Private Sub cmdLoad_Click()
    txtLinks.Text = ""
    Screen.MousePointer = vbHourglass
    DoEvents

    WebBrowser1.Navigate txtURL

    ' The rest happens in WebBrowser1_DocumentComplete.
End Sub

Private Sub WebBrowser1_DownloadComplete()
Dim doc As HTMLDocument
Dim a_link As HTMLAnchorElement
Dim txt As String

    ' List the links.
    On Error Resume Next
    Set doc = WebBrowser1.Document
    For Each a_link In doc.links
        txt = txt & a_link.href & vbCrLf
    Next a_link
    txtLinks.Text = txt

    Screen.MousePointer = vbDefault

End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated