Reading URL using Mechanize and dump all the contents of the URL to a file

Hello,
Am very new to perl , please help me here !!

I need help in reading a URL from command line using PERL:: Mechanize and needs all the contents from the URL to get into a file.

below is the script which i have written so far ,

#!/usr/bin/perl
use LWP::UserAgent;
use WWW::Mechanize;
use WWW::DecodedContent;
use LWP::Debug qw( + );
use HTTP::Headers ;
my $mech = WWW::Mechanize->new( autocheck => 1 );
$mech->status();
print "Am inside Mechanize\n" ;

my $content = $mech->decoded_content || $mech->content;
#$mech->response()->decoded_content();
$ua->default_header("Accept-Encoding" => "gzip, deflate");
#$mech = WWW::Mechanize->new ;
$ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
#$ua->default_header("Accept-Encoding" => "gzip, deflate");
$mech->get( "http://zzzzzzzzzURLzzzzzzzz" );
my $test = $mech->forms();
die "Can't even get the home page: ", $mech->response->status_line
unless $mech->success;

$mech->status();
$mech->uri();
 if ($response->is_success) {
   print "\n i am in finally";
   }
   else {
          die $response->status_line;
 }

Please feel free to provide some suggestion on changing the original script ,this is my first draft of code.

where as am getting an error " Can't call method "default_header" on an undefined value at getjan23.pl line 14. "

please let me know what am missing.

Thanks in advance

Check the wget utility, i guess it does what you need ... without having to reinvent the wheel :wink:

Hi Ctsgnb,

Thanks for your reply.

Actually in the server we dont have wget ,curl utility and we cannot install as well.

Btw, i found the answer and i was able to get the output which i supposed to get. Hope it will be useful for others who are in search of such thing. and it was pretty simple.

#!/usr/bin/perl

use strict;
use warnings;
use LWP::UserAgent;

my $req;
my $res;

my $ua = LWP::UserAgent->new;
$ua->agent("Firefox/1.5.0.10");
$ua->timeout(1000);

$req = HTTP::Request->new(GET => 'http://yyyzzzzzxxxxxxxiiiii');

$res = $ua->request($req);

if ($res->is_success) {
    print $res->content;
}
else {
    print "Error: " . $res->status . "\n";
}