René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

Fetching data from a webserver with Perl

With HTTP::Request, URI and LWP::UserAgent

use HTTP::Request;
use URI;
use LWP::UserAgent;

my $url = "http://www.adp-gmbh.ch";
my $ua  = LWP::UserAgent->new();
my $uri = URI->new($url);
my $anf = HTTP::Request->new(GET => $url);
my $ans = $ua->request($anf);
if ($ans->is_error()) {
  printf "Error -->  %s\n", $ans->status_line;
}
else {
  my $cnt = $ans->content;
  print $cnt;
}

Support for a proxy

If a webpage is to be fetched via a proxy, this can be specified with the proxy method of LWP::UserAgent:
my $ua = LWP::UserAgent->new()
$ua->proxy(http=>'http://proxy.ournet.xy:8080');

With LWP::Simple

use warnings;
use strict;

use LWP::Simple;

my $ans =
get("http://search.cpan.org/doc/GAAS/libwww-perl-5.65/lib/LWP/Simple.pm");

print $ans

Links

See also HTML::TokeParser