[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to get a string from a webpage

PP

5/24/2006 9:30:00 AM

In my daliy work there are some project budget with the form "Between
$1,000 and $ 1200" to gather The html codes for this is as following.
What's more this part is in a table
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<tr><td valign="top" class="small" colspan="2"><b>Project Budget:</b>
Between $1,000 and $1,500<br><img src="/images/spacer.gif" height="5"
width="1" border="0"><br></td></tR>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Now I want to get the Budget in such pages normally more than 30. Can
any funtion get the whole string "Between $1,000 and $ 1,500" by a
regexp or something else.
I have tried the function " contains_text" but it returns a number.
Can anyone tell me what the number means and how can it get in touch
with the string I want
btw: the money is different but the form is always the same.

Can anyone help me ?

6 Answers

aidy

5/24/2006 11:33:00 AM

0

Have a look at this HTML/XML parser

http://www.crummy.com/software/Ru...

Aidy

Dave Burt

5/24/2006 12:54:00 PM

0

PP wrote:
> In my daliy work there are some project budget with the form "Between
> $1,000 and $ 1200" to gather The html codes for this is as following.
> What's more this part is in a table
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> <tr><td valign="top" class="small" colspan="2"><b>Project Budget:</b>
> Between $1,000 and $1,500<br><img src="/images/spacer.gif" height="5"
> width="1" border="0"><br></td></tR>
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Now I want to get the Budget in such pages normally more than 30. Can
> any funtion get the whole string "Between $1,000 and $ 1,500" by a
> regexp or something else.
> I have tried the function " contains_text" but it returns a number.
> Can anyone tell me what the number means and how can it get in touch
> with the string I want
> btw: the money is different but the form is always the same.
>
> Can anyone help me ?
>

If you're using Watir (as I guess from your mention of contains_text)
then that number is probably an index into the string of the start of
that substring. So ie.text[n, 7], where n is the number you got from
ie.contains_text, should give you "Between" (7 characters).

Cheers,
Dave

bpettichord

5/24/2006 12:59:00 PM

0

Don't use contains_text. Instead use a regexp directly:

/<b>Project Budget:</b> (Between \$[0-9,]* and \$[0-9,])<br>/ ~ ie.html
match = $1

or

/<b>Project Budget:</b> (Between \$[0-9,]* and \$[0-9,])<br>/ ~
ie.cell(:class, "small").html
match = $1

PP

5/25/2006 4:24:00 AM

0

Hi Bret
I have tried the method but it seems doesn't work. The error
information is about the "~". Could you show me some code more
particularly.

Best wishes

Chris Hulan

5/25/2006 3:51:00 PM

0

Just a typo, instead of '~' should be '=~' the regexp match operator

cheers

PP

5/26/2006 12:45:00 AM

0

Thanks for all your advice, the problem has been solved.

Best wishes