Link to home
Start Free TrialLog in
Avatar of jay-are
jay-areFlag for United States of America

asked on

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()
        sr.Close()
        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: \\192.168.0.100\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!
ASKER CERTIFIED SOLUTION
Avatar of Solar_Flare
Solar_Flare

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jay-are

ASKER

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

Thanks!