Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: multiple selections in the same field using Mechanize

by keszler (Priest)
on Dec 09, 2011 at 01:02 UTC ( #942532=note: print w/ replies, xml ) Need Help??


in reply to multiple selections in the same field using Mechanize

Setting a select field with multiple values allowed is documented at http://search.cpan.org/~abeltje/Win32-IE-Mechanize-0.009/lib/Win32/IE/Mechanize.pm#$ie-%3Eselect%28_$name,_\@values_%29:

$ie->select( $name, \@values ) Given the name of a select field, set its value to the value specified. If the field is not <select multiple> and the $value is an array, only the first value will be set. Passing $value as a hash with an n key selects an item by number (e.g. {n = 3> or {n = 2,4}>). The numbering starts at 1. This applies to the current form (as set by the form() method or defaulting to the first form on the page).
So,
$ie->select( 'parms', [ 'var1', 'var2' ]); or @multi_values = ('var1','var2'); $ie->select( 'parms', \@multi_values);


Comment on Re: multiple selections in the same field using Mechanize
Download Code
Re^2: multiple selections in the same field using Mechanize
by Anonymous Monk on Dec 09, 2011 at 01:10 UTC
    ++

    :) Your reading comprehension is most excellent

      .. And thanks, A.M., for trying :)
Re^2: multiple selections in the same field using Mechanize
by Anonymous Monk on Dec 09, 2011 at 16:48 UTC

    Thank you, Keszler - that .. nearly works. The multiple fields get highlighted, but then it becomes a fail with this error,

    "Use of unitialized value in list assignment at C:\PERL..\IE\Input.pm line 115"

    ... and this is the entire script:

    ----------------------------

    my $url = "http://www.mesonet.org/index.php/weather/daily_data_retriev +al"; my $ie =Win32::IE::Mechanize->new( visible=> 1 ); my @variables = ('TAVG','DAVG','PAVG','HMAX','HMIN','HAVG','WSPD','ATO +T'); $ie->get($url); sleep 1; $ie->form_name("request"); $ie->set_fields(beginmonth=>'05'); $ie->set_fields(beginday=>'15'); $ie->set_fields(beginyear=>'2010'); $ie->set_fields(endmonth=>'07'); $ie->set_fields(endday=>'06'); $ie->set_fields(endyear=>'2010'); $ie->select( 'parms', \@variables); $ie->set_fields(stid=> $station); $ie->click("SUBMIT"); my $html = $ie->content; print $html; $ie->close;

    -----------------------

    ... any other glaring errors on my part, or is it IE::Mech?

      .. and this is the offending line 115 in Input.pm:

      %vals = map { ( $_ => undef ) } @values;

      But I'm such a newbie to Perl, I can't parse what's in the brackets?
        NM. It DOES work!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://942532]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2014-07-22 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (107 votes), past polls