Read the Source Code of a Web Page

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This tutorial describes how to read the source code of web page.

Add a WebBrowser to the form, textbox and a button.

Navigate the webbrowser to the page you like to get its source through a button click:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'when button1 cliked, webbrowser is navigated to the page
        WebBrowser1.Navigate("http://www.youtube.com")
End Sub

When page is downloaded, page source will be displayed through DocumentCompleted Event:

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        'When webbrower finish opening the page, source page is diplayed in text box
        TextBox1.Text = WebBrowser1.DocumentText
    End Sub


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.