Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

WWW::Mechanize select from dropdown

by camerlengo (Novice)
on Apr 20, 2007 at 19:40 UTC ( [id://611226]=perlquestion: print w/replies, xml ) Need Help??

camerlengo has asked for the wisdom of the Perl Monks concerning the following question:

I'm having issues parsing a page with a select multiple dropdown and need a nudge in the right direction. I'm trying to select the names 'pforumClass', 'tforumClass' and 'uforumClass' with values '__all__' from the form prior to submitting it. HTML is below, followed by a code snippet:
<form method="POST" action="/forums/cs/dispatch.cgi/_admin/util_button +Dispatch" onSubmit="return formSubmit()" name="CFO" > <b>Public Forums:<br></b><select name="pforumClass" multiple size=8> <option value="__none__" selected>-None- <option value="__all__">--All-- --snip-- </select><p> <b>Team Forums:<br></b><select name="tforumClass" multiple> <option value="__none__" selected>-None- <option value="__all__">--All-- </select><p> <b>User Forums:<br></b><select name="uforumClass" multiple> <option value="__none__" selected>-None- <option value="__all__">--All-- </select><p> <br> <br>
Code snippet is as follows:
my $mech = WWW::Mechanize->new(); $mech->get("https://www.site.com/forums/cs/dispatch.cgi/_admin/diskUsa +geForm"); $mech->form_name('CFO'); $mech->select('pforumClass','__all__'); $mech->select('tforumClass','__all__'); $mech->select('uforumClass','__all__'); $mech->click();

My LWP::Debug output informs me :

Illegal value '__all__' for field 'pforumClass' at C:/Perl/site/lib/WWW/Mechanize.pm line 1199
Illegal value '__all__' for field 'tforumClass' at C:/Perl/site/lib/WWW/Mechanize.pm line 1199
Illegal value '__all__' for field 'uforumClass' at C:/Perl/site/lib/WWW/Mechanize.pm line 1199

What am I missing? Gotta be something simple ...

Replies are listed 'Best First'.
Re: WWW::Mechanize select from dropdown
by davidrw (Prior) on Apr 20, 2007 at 23:27 UTC
    not sure what the issue is, but maybe try WWW::Mechanize's submit_form method instead?
    my $mech = WWW::Mechanize->new(); $mech->get("https://www.site.com/forums/cs/dispatch.cgi/_admin/diskUsa +geForm"); $mech->submit_form( form_name => 'CFO', fields => { pforumClass => '__all__', tforumClass => '__all__', uforumClass => '__all__', }, );
    Also maybe see if the output from mech-dump gives you any extra information ...

    And also do a die $mech->content; after the ->get() to make sure it's really the page you expect it is ...
Re: WWW::Mechanize select from dropdown
by codeacrobat (Chaplain) on Apr 21, 2007 at 22:09 UTC
    When things are odd with WWW::Mechanize try to debug/develop with WWW::Mechanize::Shell. It features interactive web browsing, form filling and can generate a WWW::Mechanize script from the recorded session. Here is a bit look'n feel.
    perl -MWWW::Mechanize::Shell -eshell (no url)>get http://google.de Retrieving http://google.de(200) http://www.google.de/>forms Form [1] GET http://www.google.de/search [f] hl=de (hidden readonly) ie=ISO-8859-1 (hidden readonly) q= (text) btnG=Google-Suche (submit) btnI=Auf gut Glück! (submit) meta= (radio) [*|lr=lang_de|cr=countryDE +]
Re: WWW::Mechanize select from dropdown
by Cody Pendant (Prior) on Apr 21, 2007 at 12:58 UTC
    Shouldn't you be trying to select "--All--", which is the content of that element as shown in the interface, rather than "__all__" which is the value hidden in the HTML?


    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://611226]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-18 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found