• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 678
  • Last Modified:

Capture text from website using VB

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!
1 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.
jay-areAuthor Commented:
Yeah you were right, I was calling the function incorrectly.  Basically the reader was reading nothing...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now