in reply to how smart www::mechanize can be?

y.. WWW::Mechanize uses HTML::Form underneath which has a find_input method..
my $form = $mech->current_form; warn $form->find_input( 'shopwizard' );
Update: added loop-age:
my $form; foreach ( $mech->forms ){ if( $_->find_input('shopwizard') ){ $form = $_; last; } } # OR (yet another way; slightly less efficient): my @shopwizardForms = grep { $_->find_input( 'shopwizard' ) } $mech->f +orms; # or just: my ($shopwizardForm) = grep { $_->find_input( 'shopwizard' ) } $mech-> +forms;

Replies are listed 'Best First'.
Re^2: how smart www::mechanize can be?
by Anonymous Monk on Mar 28, 2006 at 19:43 UTC
    Hi. I tried
    my $form; foreach ( $mech->forms ){ if( $_->find_input( 'shopwizard' )){ $form = $_; last; } } print "---------------------- form was $form"; $mech->submit_form( form_number => $form, fields => { shopwizard => "Winter Love Usuki Set", criteria => 'exact' } );
    and it's erroring out now. When I print the $form, it prints HTML::Form=HASH(..). So if the $form has this, could this mean it's not passing the right information to my form?
      my $forms = $mech->forms(); my $form_num; for (0..$#$forms) { if ($forms->[$_]->find_input('shopwizard')) { $form_num = $_ + 1; last; } } die("Unable to find shopwizard form\n") unless $form_num; $mech->submit_form( form_number => $form_num, fields => { shopwizard => "Winter Love Usuki Set", criteria => 'exact' } );