Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

WWW::Mechanize input value

by packetstormer (Monk)
on Aug 04, 2012 at 13:48 UTC ( #985430=perlquestion: print w/ replies, xml ) Need Help??
packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Hello

I have a very small, standard connection to website that gets the value of an input field. I can get the value and print it fine, but I cannot assign it to a variable!!! Can anyone see why this is:

.... my $mech = WWW::Mechanize->new(agent => 'Windows IE 6'); my $url = "https://www.somesite.com"; $mech->get($url); # This next line prints, to screen, the value as expected print "Value: " . $mech->field('sessionid'); # These next 2 lines prints nothing! my $sessionid = $mech->field('sessionid'); print "$sessionid\n";
Can anyone see why this might be!?

Comment on WWW::Mechanize input value
Download Code
Re: WWW::Mechanize input value
by Athanasius (Monsignor) on Aug 04, 2012 at 14:40 UTC

    Hello packetstormer,

    The WWW::Mechanize->field method is actually for setting the field value. Your first call sets the value of 'sessionid' to undef (since no second argument is supplied), and returns the previous value. Your second call gets the new, empty value.

    Use the WWW::Mechanize->value method instead. This gets the field value without the side effect of resetting it:

    my $mech = WWW::Mechanize->new(agent => 'Windows IE 6'); my $url = "https://www.somesite.com"; $mech->get($url); print "Value: '", $mech->value('sessionid'), "'\n"; my $sessionid = $mech->value('sessionid'); print "\$sessionid = '$sessionid'\n";

    See WWW::Mechanize, under “FIELD METHODS.”

    HTH,

    Athanasius <°(((><contra mundum

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-09-01 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls