Extract Links or URLs from A Web Page – Visual Basic 6 (VB6)

Extracting Links Using VB6

This is an easy way to extract links from a web page using a web browser control and a reference to Microsoft HTML Object Library. This code will extract all links in the href property of the A tag and save them to a text file named urllist.

  • Create a form.
  • Add reference to Microsoft Html Object Library.
  • Add a web browser control.
  • Add a List Box
  • Add a command button.

VB Code:

 

Private Sub Command1_Click()
    Dim c
    Dim aLink As Object

    For Each aLink In WebBrowser1.Document.All.tags("A")
        List1.AddItem aLink.href
    Next aLink

    Open App.Path & "\urllist.txt" For Output As #1
        For c = 0 To List1.ListCount - 1
            Print #1, List1.List(c)
        Next
    Close #1
End Sub

Private Sub Form_Load()
    WebBrowser1.Navigate "http://www.fatherofcents.com/"
End Sub

Download: Extracting Links in Visual Basic Extract-Links-VB6.zip

6 thoughts on “Extract Links or URLs from A Web Page – Visual Basic 6 (VB6)”

  1. Private Sub Command1_Click()
    Dim c
    Dim aLink As Object

    For Each aLink In WebBrowser1.Document.All.tags(“A”)
    ‘ Add below to filter links

    If Instr(aLink.href, “your keyword”) then
    List1.AddItem aLink.href
    End If
    Next aLink

    Open App.Path & “\urllist.txt” For Output As #1
    For c = 0 To List1.ListCount – 1
    Print #1, List1.List(c)
    Next
    Close #1
    End Sub

    Private Sub Form_Load()
    WebBrowser1.Navigate “http://www.fatherofcents.com/”
    End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *