Capture text from website using VB

Posted on 2007-10-05
Medium Priority
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 vb.net.  This is a WEBFORM.  Here is the code I have now:

MsgBox.Text = (GetHtmlPage("http://www.google.com"))
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("http://www.google.com"))

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

Solar_Flare earned 2000 total points
ID: 20032173
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

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


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

850 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