Capture text from website using VB

Posted on 2007-10-05
Last Modified: 2010-08-05
Hello Experts:

I'm trying to capture text from a website.  I got some previous help here but was unable to get to a working solution.  I need to be able to do this from an aspx page using  This is a WEBFORM.  Here is the code I have now:

MsgBox.Text = (GetHtmlPage(""))
Function GetHtmlPage(ByVal strURL As String) As String
        Dim strResult As String
        Dim objResponse As WebResponse
        Dim objRequest As WebRequest = HttpWebRequest.Create(strURL)
        objResponse = objRequest.GetResponse()
        Dim sr As New StreamReader(objResponse.GetResponseStream())
        strResult = sr.ReadToEnd()
        Return strResult
    End Function

When I load the page I get the following error:

Object reference not set to an instance of an object.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 100:            MsgBox.Text = (GetHtmlPage(""))

Source File: \\\wwwroot\9723528000\BBWeb\selectedoptions.aspx.vb    Line: 100

How can I get this to work inside my webform?  I have to focus on the specific text I need but for now I am just trying to pull the text on an entire page to see if it works.  Help!
Question by:jay-are
    LVL 15

    Accepted Solution

    have you tested this when running locally on the visual studio development server? if it gives the same error then you can step through the code and inspect the Locals to see what is assigned to each variable and see where the null reference is occurring.

    Author Comment

    Yeah you were right, I was calling the function incorrectly.  Basically the reader was reading nothing...


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    This video discusses moving either the default database or any database to a new volume.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now