?
Solved

Select specific text?

Posted on 2007-10-08
5
Medium Priority
?
246 Views
Last Modified: 2010-04-23
Hello Experts:

I'm using a webform to populate a textbox with text from a website.  I use this function:

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()
        msgbox.Text = strResult
        sr.Close()
    End Function

This works for me just fine but I have no clue how to get the specific text I need from that webpage.  There is a table on this page:

<table cellspacing="0" class="srpFooterTable">
        <tr>
            <td colspan="2"><a href="/help/cms_article_page.jsp?contentid=22594#21940185" class="bold-link">Advertised Price Range</a> for this search</td>
        </tr>
<tr>
            <td class="srpFooterTD">$12,900</td>
            <td>Highest price</td>
        </tr>
        <tr>
            <td class="srpFooterTD">$7,499</td>
            <td>Lowest price</td>
        </tr>
        <tr>
            <td class="srpFooterTD">$9,449</td>
            <td>Average price</td>
        </tr>
</table>
I really want to grab those three dollar values and store them in three different textboxes.  How do I do this?
0
Comment
Question by:jay-are
  • 3
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
Solar_Flare earned 2000 total points
ID: 20037192
regular expressions would be the easiest

dim r as new Regex(">$([0-9|,|.]+)<")
dim mc as MatchCollection = r.matches(htmlstring)
for each m as match in mc
   dim s as string = m.Groups(1).ToString()
   ''do something with s
next
0
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 20037206
oops the $ sign should be escaped

\$
0
 

Author Comment

by:jay-are
ID: 20037208
What is regex and MatchCollection?  It doesn't recognize those.
0
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 20037963
Imports System.Text.RegularExpressions
0
 

Author Comment

by:jay-are
ID: 20040756
Yeah this worked for the most part.  

dim r as new Regex(">\$([0-9|,|.]+)<")
dim mc as MatchCollection = r.matches(htmlstring)
for each m as match in mc
   dim s as string = m.Groups(1).ToString()
   textbox1.text = s
next

When I put in something like TextBox1.text = Textbox1.Text & " " & s, I get every dollar amount on that page.  As it is, I just get the final number from that list that I wanted: Average.  Thanks for your help!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 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