[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Capturing text from I.E.

Posted on 2007-09-29
9
Medium Priority
?
227 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!
0
Comment
Question by:jay-are
  • 5
  • 4
9 Comments
 
LVL 11

Expert Comment

by:AkisC
ID: 19985351
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
0
 
LVL 11

Accepted Solution

by:
AkisC earned 2000 total points
ID: 19985396
Here is another more like .NET function

Imports System.IO
Imports System.Net

MsgBox(GetHtmlPage("http://www.google.com"))

    Shared 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()
        Using sr As New StreamReader(objResponse.GetResponseStream())
            strResult = sr.ReadToEnd()
            sr.Close()
        End Using
        Return strResult
    End Function
0
 

Author Comment

by:jay-are
ID: 19985423
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:jay-are
ID: 19987269
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.

0
 
LVL 11

Expert Comment

by:AkisC
ID: 19987492
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?

0
 

Author Comment

by:jay-are
ID: 19988129
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.
0
 
LVL 11

Expert Comment

by:AkisC
ID: 19988725
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
0
 

Author Comment

by:jay-are
ID: 19990393
Ok well thanks for your help so far!
0
 
LVL 11

Expert Comment

by:AkisC
ID: 19992744
Thank you jay-are
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question