Published in: Perl
URL: http://codedump.jonasjohn.de/snippets/lwp_example.htm
Shows how to load a text file Another good resource: Web Client Programming with Perl.
#!/usr/bin/perl # load LWP library: use LWP::UserAgent; use HTML::Parse; # define a URL my $url = 'http://www.jonasjohn.de'; # create UserAgent object my $ua = new LWP::UserAgent; # set a user agent (browser-id) # $ua->agent('Mozilla/5.5 (compatible; MSIE 5.5; Windows NT 5.1)'); # timeout: $ua->timeout(15); # proceed the request: my $request = HTTP::Request->new('GET'); $request->url($url); my $response = $ua->request($request); # # responses: # # response code (like 200, 404, etc) my $code = $response->code; # headers (Server: Apache, Content-Type: text/html, ...) my $headers = $response->headers_as_string; # HTML body: my $body = $response->content; # print the website content: # print $body; # do some parsing: my $parsed_html = HTML::Parse::parse_html($body); # extract all links (a, body, img) my ($link) = @$_; # print link: }
You need to login to post a comment.
