#!/usr/bin/perl

use LWP::UserAgent;

$url = “http://www.google.com”;
readURL($url);

sub readURL {
($url) = (@_);
$ua = LWP::UserAgent->new;
$ua->agent(“Mozilla/8.0”); # pretend we are very capable browser

$req = HTTP::Request->new(GET => $url);
$req->header(‘Accept’ => ‘text/html’);
$res = $ua->request($req); # send request
if ($res->is_success) { # check the outcome
print $res->content;
}
else {
print “Error: ” . $res->status_line . “\n”;
}
}

Advertisements