Secure site Re-login using cookies and WWW::Mechanize

"[email protected]" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Organization http://groups.google.com
Message-ID <[email protected]>
I am trying to write a script to automatically login to a secure site.
I want to use cookies to login to the site without specifying the
username and password. This would be similar to "remembering me" option
that some sites have which I believe just uses cookies.

use strict;
use WWW::Mechanize;
use HTTP::Cookies;

my $outfile = "Result.htm";
my $url = "https://www.google.com/accounts/ServiceLogin?";
my $username = "username";
my $password = "password";
my $cookiefile = 'cookies.txt';
my $cookie_jar = HTTP::Cookies->new(File => $cookiefile, autosave =>
1);
my $mech = WWW::Mechanize->new();
$mech->cookie_jar($cookie_jar);
$mech->agent('Mozilla/4.0');
$mech->get($url);
$mech->form_number(1);
$mech->set_visible( $username, $password ) ;
$mech->click();
$mech->follow_link(text => "Click here if your browser does not
automatically redirect you.", n => 1);

##print out current page
my $output_page = $mech->content();
open(OUTFILE, ">$outfile");
print OUTFILE "$output_page";
close(OUTFILE);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.