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

asked on

Capturing text from I.E.

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!
Avatar of AkisC
AkisC
Flag of Greece image

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
ASKER CERTIFIED SOLUTION
Avatar of AkisC
AkisC
Flag of Greece image

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

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.
Avatar of jay-are

ASKER

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.

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?

Avatar of jay-are

ASKER

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.
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
Avatar of jay-are

ASKER

Ok well thanks for your help so far!
Thank you jay-are