Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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 = "https://mail.yahoo.co.in.com/"; 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.

Comment on How to acess the websites by using www::Mechanize module
Download Code
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 (https://mail.yahoo.co.in.com/), 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2014-10-23 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls