Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^6: WGET equivalent

by downer (Monk)
on Feb 04, 2008 at 15:55 UTC ( [id://665985]=note: print w/replies, xml ) Need Help??


in reply to Re^5: WGET equivalent
in thread WGET equivalent

here is an example of my script with most of the details eliminated, still producing a  permission denied error. Most mysterious!
#!/usr/local/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser carpout); use lib qw(/usr/lib/perl5/vendor_perl/5.8.6/LWP /usr/lib/perl5/vendor_ +perl/5.8.6 / /usr/lib/perl5/vendor_perl/5.8.6/LWP/UserAgent.pm); use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->agent('Mozilla/5.0'); my $current_page = "http://www.perlmonks.org"; my $response = $ua->get($current_page); my $data = $response->content if($response->is_success) or die "not su +ccessful $!\n"; if($data){ print "page: $current_page\n$data\ndone", length($data); } else { print "no data\n"; }

Replies are listed 'Best First'.
Re^7: WGET equivalent
by moritz (Cardinal) on Feb 04, 2008 at 17:32 UTC
    Your script works for me.

    BTW the use lib ... line looks like cargo cult programming - you don't know what it means, but write it nevertheless in the hope that it will help.

    With use lib @list you specify directories in which perl searches for modules. The last entry doesn't look a like a directory at all, so remove it. And it's somewhat unusual to have modules in /, so that probably isn't needed as well.

Re^7: WGET equivalent
by Corion (Patriarch) on Feb 04, 2008 at 17:33 UTC

    Not mysterious. LWP::UserAgent does not set $!. The "permission denied" message you're seeing is just an artifact of $! having some value resulting from some system call.

    I recommend using $response->as_string() to inspect what you get back, and

    die $response->status_line;

    (as the documentation of HTTP::Response suggests).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://665985]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-25 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found