jay-are
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(strU RL)
objResponse = objRequest.GetResponse()
Dim sr As New StreamReader(objResponse.G etResponse Stream())
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.NullReferenceExcept ion: 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\97 23528000\B BWeb\selec tedoptions .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!
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(strU
objResponse = objRequest.GetResponse()
Dim sr As New StreamReader(objResponse.G
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.NullReferenceExcept
Source Error:
Line 100: MsgBox.Text = (GetHtmlPage("http://www.google.com"))
Source File: \\192.168.0.100\wwwroot\97
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!