in reply to Re^3: using WWW::Mechanize and receiving Unauthorized at line $mech->get($url);
in thread using WWW::Mechanize and receiving Unauthorized at line $mech->get($url);

Here is some part of my Script after I assign the username and password. when I run the scrip, I get Unauthorized error at $mech->get($url); my $mech = WWW::Mechanize->new();  $mech->get($url);  $mech->form_name('loginform');  $mech->field(login => $username);  $mech->field(passwd => $password);  $mech->click();  my $outpage = $mech->content();  open(OUTFILE, ">$outfile");  print OUTFILE "$outpage";

Replies are listed 'Best First'.
Re^5: using WWW::Mechanize and receiving Unauthorized at line $mech->get($url);
by tomfahle (Priest) on May 09, 2009 at 05:50 UTC

    See WWW:::Mechanize and credentials and the WWW::Mechanize::Cookbook especially Fetch a password-protected page.

    Then try do fetch the page manually. Double check if Firefox has already stored a username and password for you.

    Next step is to build your code in small steps to see whats going on:

    #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new( stack_depth => 1, timeout => 180, autocheck => 1 ); # Part 1 my $url = 'http://somewhere.tld'; $mech->get($url); __END__ # Part 2 # my $username = ''; my $password = ''; $mech->form_name('loginform'); $mech->field(login => $username); $mech->field(passwd => $password); $mech->click(); # Which button? # Part 3 my $outpage = $mech->content(); my $outfile = 'output.html'; # Always use the three argument form of open open(OUTFILE, ">", $outfile) or die $!; print OUTFILE "$outpage"; close(OUTFILE) or die $!;

    BTW: Please read Markup in the Monastery.

    Hope this helps.

Re^5: using WWW::Mechanize and receiving Unauthorized at line $mech->get($url);
by ww (Archbishop) on May 08, 2009 at 23:16 UTC