meanroc has asked for the wisdom of the Perl Monks concerning the following question:

Hello guys,I want to print the source code of a website with this code:

#!/usr/bin/perl use warnings; use strict; use LWP; my $alvo; chomp($alvo=<STDIN>); my $url="$alvo"; my $lwp=LWP::UserAgent->new; my $resultado=$lwp->get ($url); my @res=$resultado->content; foreach(@res){ print "$_"; }

And in the <STDIN> I put "http://www.meuhumor.com.br", and when I run, compiles a source code with the error 1010 "enable cookie", how do I enable the cookie? Tks

Replies are listed 'Best First'.
Re: Enable cookie
by atcroft (Abbot) on Jan 27, 2014 at 22:36 UTC

    Try adding the following (lifted and adapted from the LWP::UserAgent docs) just before your get() call:

    $lwp->cookie_jar({ file => "$ENV{HOME}/.cookies.txt" });

    You may wish to specify a different file name for the cookies, or possibly a temporary file that is removed at the end of execution if you do not wish that data to be retained.

    Hope that helps.

Re: Enable cookie (javascript )
by Anonymous Monk on Jan 28, 2014 at 00:30 UTC

      Bah, I was wrong, LWP doesn't do a cookie jar by default, thats what WWW::Mechanize does, and one of the reasons I use WWW::Mechanize by default

      WWW::Mechanize is convenient like that :)