serf has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to fill out a form in a nasty page (baaad HTML!) using Corion's handy utility WWW::Mechanize::Shell.
Everything I've tried like:
GRRR!!!
The form includes this source:
which comes up in WWW::Mechanize::Shell as:<form name="someForm" method="post" action="/some_form.do"> ... <input type="checkbox" name="dayOfWeek" value="SUN" >Sun <input type="checkbox" name="dayOfWeek" value="MON" >Mon <input type="checkbox" name="dayOfWeek" value="TUE" >Tue <input type="checkbox" name="dayOfWeek" value="WED" >Wed <input type="checkbox" name="dayOfWeek" value="THU" >Thurs <input type="checkbox" name="dayOfWeek" value="FRI" >Fri <input type="checkbox" name="dayOfWeek" value="SAT" >Sat ... </form>
dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|SUN/Sun] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|MON/Mon] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|TUE/Tue] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|WED/Wed] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|THU/Thurs] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|FRI/Fri] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|SAT/Sat ]
tick dayOfWeek SUN or tick or on or SUN or tick SUN on
just returns errors like:
and|SUN (checkbox)dayOfWeek> [] tick dayOfWeek SUN Illegal value 'tick dayOfWeek SUN' for field 'dayOfWeek' at /usr/lib/p +erl5/site_perl/5.8.0/WWW/Mechanize/FormFiller.pm line 124
and|SUN (checkbox)dayOfWeek> [] tick Illegal value 'tick' for field 'dayOfWeek' at /usr/lib/perl5/site_perl +/5.8.0/WWW/Mechanize/FormFiller.pm line 124
If I just hit <enter> on all of them so they are not ticked then I get this in the script output:|SUN (checkbox)dayOfWeek> [] tick SUN on Illegal value 'tick SUN on' for field 'dayOfWeek' at /usr/lib/perl5/si +te_perl/5.8.0/WWW/Mechanize/FormFiller.pm line 124
Which looks perfectly braindead :o( :o($formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' );
The man page just says:
tick Set checkbox marks Syntax: tick NAME VALUE(s) If no value is given, all boxes are checked. untick Remove checkbox marks Syntax: untick NAME VALUE(s) If no value is given, all marks are removed.
and nothing else mentions checkboxes...
When I check the first two boxes in Firefox and look at the result using LiveHTTPHeaders I see this is being posted:
... &dayOfWeek=SUN&dayOfWeek=MON& ...
Is it possible to get WWW::Mechanize to send the same?
I tried this:
and I get this back:#!/usr/bin/perl use warnings; use strict; use WWW::Mechanize; use WWW::Mechanize::FormFiller; my $agent = WWW::Mechanize->new( autocheck => 1 ); my $formfiller = WWW::Mechanize::FormFiller->new(); $agent->form(1) if $agent->forms and scalar @{$agent->forms}; $agent->get('http://server/page_with_form/'); $agent->form(1) if $agent->forms and scalar @{$agent->forms}; $agent->form_number(1); $formfiller->add_filler( 'dayOfWeek' => Fixed => 'SUN' ); $formfiller->fill_form($agent->current_form); $agent->click('');
Lovely! :o( If I get cheeky and try something like:$ ./try.pl Illegal value 'SUN' for field 'dayOfWeek' at /usr/lib/perl5/site_perl/ +5.8.0/WWW/Mechanize/FormFiller.pm line 124
I get:$formfiller->add_filler( 'dayOfWeek' => 'SUN' => 'on' );
$ ./try.pl Can't locate WWW/Mechanize/FormFiller/Value/SUN.pm in @INC (@INC conta +ins: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl .) at (eval 23) line 2. BEGIN failed--compilation aborted at (eval 23) line 2. WWW::Mechanize::FormFiller::load_value_class('SUN') called at +/usr/lib/perl5/site_perl/5.8.0/WWW/Mechanize/FormFiller.pm line 65 WWW::Mechanize::FormFiller::add_filler('WWW::Mechanize::FormFi +ller=HASH(0x995ebdc)','dayOfWeek','SUN','on') called at ./try.pl line 30
what am I doing wrong?
Is it to do with bug #2700: Set/Reset multiple checkboxes?
Or is the bad HTML making WWW::Mechanize / WWW::Mechanize::Shell bork? (that's kind of what it looks like to me)
Edited by planetscape - added readmore tags ( keep:0 edit:29 reap:0 )
Back to
Seekers of Perl Wisdom