Get Links and the Number of Links of a Website

In this article, we will create a program that get the links and the number of links of a website. With a link, users can navigate to another page, window, or Help topic; display a definition; initiate a command; or choose an option. A link is text or a graphic that indicates that it can be clicked, typically by being displayed using the visited or unvisited link system colors, examples are hyperlinks. 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 3. Add a WebBrowser named WebBrowser so that we can view its link. Now, add http://www.sourcecodester.com to the URL Property of the WebBrowser. property 3. Next, add one TextBox named TextBox1 for displaying the links of the webBrowser and a Label named Label1 for viewing the number of links for a website. Add also one Button named Button1 for getting the links and number of links of a website. Design your layout like this one: design 4.Put this code to your Button1_Click. This will trigger to get the number of links and the links of the webbrowser.
  1.  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim tempNum As Integer
  3.         Dim tempString As String = ""
  4.         For tempNum = 1 To WebBrowser1.Document.Links.Count - 1
  5.             tempString = tempString & WebBrowser1.Document.Links(tempNum).InnerHtml & vbCrLf
  6.         Next
  7.         TextBox1.Text = tempString
  8.         Label1.Text = WebBrowser1.Document.Links.Count & " links."
  9.     End Sub

Explanation:

We have initialized tempNum as Integer and tempString as String as equal to nothing. Next we have created a for next loop that the tempNum variable will start a value of 1 up to the number of links of the WebBroswer minus the value of 1. The tempString now will be equal to the source of the WebBrowser that also contains the number of links held by the tempNum variable. vbCrLf here is for the next line. Now, we passed the value of our links (tempString variable) to TextBox1. and the number of links will now be displayed in our Label1.

Output:

Loading of the Sourcecodester site from the WebBrowser. output Click the Button to get the links and the number of links from the Sourcecodester website. output Download the source code below and try it! :) For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment