We help IT Professionals succeed at work.

Capturing text from I.E.

jay-are
jay-are asked
on
257 Views
Last Modified: 2010-04-23
Hello Experts:

I'm interested in capturing the text on a webpage.  When I visit the website it displays some dollar amounts at the bottom of the page that I want to capture and store in a sql table if its possible.  

Looks like this:
Advertised Price Range for this search
    $xx,xxx  Highest price
    $x,xxx    Lowest price
    $x,xxx    Average price

Is it possible to capture these values?  If someone can get me started in the right direction I'd really appreciate it!
Comment
Watch Question

CERTIFIED EXPERT

Commented:
Add a reference to your project of MSXML2.dll

        Dim xmlhttp As Object = CreateObject("MSXML2.ServerXMLHTTP")
        Dim url As String = "http://www.google.com"
        xmlhttp.open("POST", url, False)
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
        xmlHTTP.send()
        Dim ViewHTMLCode As String = xmlHTTP.responseText
        xmlHTTP = Nothing
        MsgBox(ViewHTMLCode)

ViewHTMLCode has html code of google site.
Do some reasearch and isolate the values you want
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for the response.  I'll try to work on this tomorrow a.m. and post some questions then about capturing the specific text that I need.

Author

Commented:
What exactly should MsgBox be?  I setup a multi-line textbox and did
MsgBox.Text = GetHtmlPage("http://etc")

I had to alter the function as well:
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 it gives me an object reference error.  Not set.

CERTIFIED EXPERT

Commented:
When you open e.g."http://www.google.com" in I.E. you see the page formated
If you right click on the page and select View Source you see the code behind.
GetHtmlPage-->is the code behind

So, you select the portion of the code you want to read from like
dim sStr as string=GetHtmlPage("http://www.google.com")
dim x as integer = instr(sStr,"whatyouarelookingfor")
sStr=mid(sStr,x+1)
then you eliminate various tags and find/extract the values you want
'
As for the error....
Did you write at the top of your form?
Imports System.IO
Imports System.Net
-also-
I use the code (without your alerting) with Windows.Forms
Are you using it with asp.net?

Author

Commented:
I'm using a webform.  Vb.net with asp.net.  I couldn't use this particular code:

Using    
End Using

I just declared sr instead of "Using" and removed the End Using.

I did put the imports in the top of my vb page.
CERTIFIED EXPERT

Commented:
If the code does not work try using the http://#19985351
If this does not do your job, then someone else may help you. I have not much expirience with webforms

Author

Commented:
Ok well thanks for your help so far!
CERTIFIED EXPERT

Commented:
Thank you jay-are
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.