[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Mechanize: find form with 'id' rather than 'name'?

Peter Szinek

1/31/2007 11:19:00 AM

This is what I am doing:

my_form = doc.forms.with.name(formname).first

This is what I want:

my_form = doc.forms.with.id(id_string).first

but somehow Mechanize does not like it.

Maybe because id collides with Object.id?

My problem is that the from does *not* have a 'name' attribute in the
html - so apparently I can not use that to locate it - therefore I would
like to use 'id' - or what else should I do?

Thanks,
Peter

__
http://www.rubyra...

5 Answers

andy

1/31/2007 1:45:00 PM

0


On Jan 31, 2007, at 5:18 AM, Peter Szinek wrote:

> My problem is that the from does *not* have a 'name' attribute in
> the html - so apparently I can not use that to locate it -
> therefore I would like to use 'id' - or what else should I do?

I haven't dug into the Ruby Mech yet, but the Perl version lets you
pick the Nth form on the page.

--
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance





Mat Schaffer

1/31/2007 1:55:00 PM

0

On Jan 31, 2007, at 8:44 AM, Andy Lester wrote:
> On Jan 31, 2007, at 5:18 AM, Peter Szinek wrote:
>> My problem is that the from does *not* have a 'name' attribute in
>> the html - so apparently I can not use that to locate it -
>> therefore I would like to use 'id' - or what else should I do?
> I haven't dug into the Ruby Mech yet, but the Perl version lets you
> pick the Nth form on the page.

Ruby's should have a Page#forms that works like an array.

Peter Szinek

1/31/2007 2:12:00 PM

0

Mat Schaffer wrote:
> On Jan 31, 2007, at 8:44 AM, Andy Lester wrote:
>> On Jan 31, 2007, at 5:18 AM, Peter Szinek wrote:
>>> My problem is that the from does *not* have a 'name' attribute in the
>>> html - so apparently I can not use that to locate it - therefore I
>>> would like to use 'id' - or what else should I do?
>> I haven't dug into the Ruby Mech yet, but the Perl version lets you
>> pick the Nth form on the page.
>
> Ruby's should have a Page#forms that works like an array.
Yeah, you can do

my_form = doc.forms[0]

but all I have is the id attribute of the form I am looking for. (i.e.
not the index of the form I am looking for).

So currently I am looping through all the forms and comparing the
current form's id (through form_node.attributes['id']) with the id I am
looking for.

Is there a better way to do this? Or is this OK?

Peter

__
http://www.rubyra...


Logan Capaldo

1/31/2007 3:35:00 PM

0

On Wed, Jan 31, 2007 at 08:18:37PM +0900, Peter Szinek wrote:
> This is what I am doing:
>
> my_form = doc.forms.with.name(formname).first
>
> This is what I want:
>
> my_form = doc.forms.with.id(id_string).first
>
> but somehow Mechanize does not like it.
>
> Maybe because id collides with Object.id?
>
> My problem is that the from does *not* have a 'name' attribute in the
> html - so apparently I can not use that to locate it - therefore I would
> like to use 'id' - or what else should I do?
>
Here's at least one way:
if doc is your instance of WWW::Mechanize:
my_form = (doc.page/:form).find { |elem| elem['id'] == id_string }

(Of course if you did doc = mech_instance.page, then it's
(doc/:form).find ...)

> Thanks,
> Peter
>
> __
> http://www.rubyra...

Joe Steel

5/27/2010 6:21:00 PM

0

"lab~rat >:-)" <chase@cheeze.net> wrote in
news:832tv5pf7ascnqja6ecg71fbfh5hog5c9v@4ax.com:

> On Thu, 27 May 2010 09:28:05 -0500, Joe Steel <Admin1902@joesteel.org>
> puked:
>
>>
>> No it doesn't.
>>
>> Quite a few well-educated, hard-working guys are barely getting by.
>>
>> Capitalists pay no more than they have to pay to get what they want.
>> That may be lawful and economically efficient but it's not equitable.
>> Workers deserve a seat at the table not merely the scraps which fall
>> on the floor.
>
> Clearly, the lower tier slackers get the scraps. The good workers
> that are properly trained and motivated demand higher wages. This is
> a foreign concept to you?
>
>

Have you heard any of the stories of engineers who have been out of work
for years? What about all the tool and die makers who workd in auto
manufacturing? Have you heard about them?