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

how can I fetch value from a combo box using Mechanize module

Replies are listed 'Best First'.
Re: WWW-Mechanize
by jbrugger (Parson) on Apr 18, 2005 at 06:09 UTC
    What did you try so far?
    Using WWW::Mechanize you'd be able to use : $mech->value( $name, $number ),
    but i assume you know since you've read the documentation?... :

    $mech->value( $name, $number )
    Given the name of a field, return its value. This applies to the current form (as set by the form() method or defaulting to the first form on the page).

    The option $number parameter is used to distinguish between two fields with the same name. The fields are numbered from 1.

    If the field is of type file (file upload field), the value is always cleared to prevent remote sites from downloading your local files. To upload a file, specify its file name explicitly.

    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
Re: WWW-Mechanize
by eibwen (Friar) on Apr 18, 2005 at 06:36 UTC
    If you want to query known fields, use the method described by jbrugger above; however, if you want to output the current values for all select inputs on a page:

    #!/usr/bin/perl -w use strict; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get("http://some.domain.tld/form.html"); foreach ($mech->forms) { print $_->value,"\n" foreach ($_->find_input( +undef,'option')); }

    See Also: WWW::Mechanize and HTML::Form