locked
Get a Web Page Source RRS feed

  • Question

  • How do I get the source of a web-page with Visual Basic 2010?

     

    E.g.

    GetURL("http://example.com")

    Tuesday, April 27, 2010 5:21 PM

Answers

  • You can use WebClient.DownloadString or WebClient.DownloadData to get source of web-page.

    Dim client As New System.Net.WebClient
    Dim source As String = client.DownloadString("http://www.example.com")

    Gaurav Khanna
    Tuesday, April 27, 2010 6:21 PM
  • Thank you Gaurav for your friendly help and good suggestions.

     

    Hi jSherz,

    Welcome to MSDN forums!

    Additionally, here is a quick way to retrieve web page source HTML code via invisible WebBrowser control.

    WebBrowser.Visible = False

    WebBrowser.Navigate("http://www.example.com")

    Dim htmlSource As String = WebBrowser1.DocumentText.ToString

     

    By the waty, you can easily get web page body text content like this:

    Dim Text As String = WebBrowser1.Document.Body.InnerText

    WebBrowser.DocumentText Property (System.Windows.Forms)

    http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documenttext.aspx

     

     

    Best regards,
    Martin Xie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 29, 2010 3:39 AM
    Moderator

All replies

  • You can use WebClient.DownloadString or WebClient.DownloadData to get source of web-page.

    Dim client As New System.Net.WebClient
    Dim source As String = client.DownloadString("http://www.example.com")

    Gaurav Khanna
    Tuesday, April 27, 2010 6:21 PM
  • Thank you Gaurav for your friendly help and good suggestions.

     

    Hi jSherz,

    Welcome to MSDN forums!

    Additionally, here is a quick way to retrieve web page source HTML code via invisible WebBrowser control.

    WebBrowser.Visible = False

    WebBrowser.Navigate("http://www.example.com")

    Dim htmlSource As String = WebBrowser1.DocumentText.ToString

     

    By the waty, you can easily get web page body text content like this:

    Dim Text As String = WebBrowser1.Document.Body.InnerText

    WebBrowser.DocumentText Property (System.Windows.Forms)

    http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documenttext.aspx

     

     

    Best regards,
    Martin Xie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 29, 2010 3:39 AM
    Moderator