Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

How to acess the websites by using www::Mechanize module

by perladdict (Chaplain)
on Jun 20, 2006 at 14:14 UTC ( #556396=perlquestion: print w/replies, xml ) Need Help??
perladdict has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I am tring to acess the website by using fallowing code.
#!c:\\perl\\bin use strict; use WWW::Mechanize; use HTTP::Cookies; use LWP::Debug qw(+); my $outfile = "out.htm"; my $url = ""; my $username = "rspy_sedam"; my $password = "xxxx"; my $mech = WWW::Mechanize->new(); $mech->cookie_jar(HTTP::Cookies->new()); $mech->get($url); $mech->form_name('login to yahoo!'); $mech->field(login => $username); $mech->field(passwd => $password); $mech->click(); $mech->follow_link(text => "click here", n => 1); my $output_page = $mech->content(); open(OUTFILE, ">$outfile"); print OUTFILE "$output_page"; close(OUTFILE);
Its giving an error as"cann't call method n undefined value".pls suggest me in a way that i can login to web successfully,so that i can proceed for doing other web related programming.

Replies are listed 'Best First'.
Re: How to acess the websites by using www::Mechanize module
by Corion (Pope) on Jun 20, 2006 at 14:22 UTC

    Please, please do give us the exact error message you're getting, not some vaguely guessed transcription of what you remember as the potential error message.

    Let me go out on a limb and guess, from the URL you're using (, that you don't have Crypt::SSLeay or IO::SSLeay installed. LWP (and WWW::Mechanize) need it to access https URLS.

    As a general hint, you should really, really enable either the autocheck feature - that way, WWW::Mechanize will tell you whenever one of your requests fails:

    my $mech = WWW::Mechanize->new( autocheck => 1 );

    Alternatively, you should check the return values when requesting a website:

    $mech->get($url); $mech->success or die "Couldn't retrieve >>$url<<: " . $mech->response +->as_string;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://556396]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2017-12-12 18:00 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (335 votes). Check out past polls.