#!/usr/bin/perl

use strict;
use HTML::LinkExtor;
use LWP::UserAgent;

my $url = shift @ARGV or die "Usage: $0 url\n";

# Create a Object reference to the UserAgent
my $ua = LWP::UserAgent->new();

# what page do I want?
my $req = HTTP::Request->new( GET => $url );
$req->header('Accept' => 'text/html');

# actually go out and get the page
my $res = $ua->request($req);

# error checking, did we get the page
if ( $res->is_success )
{
    my $page = $res->content();

    # now parse the html that we got, for each link, run print_the_link()
    my $parser = HTML::LinkExtor->new(\&print_the_link, $url);
    $parser->parse($page);
}
else
{
    die "Error: " . $res->status_line . "\n";
}

sub print_the_link {
    my ($tag, %links) = @_;
    print "$tag @{[%links]}\n";
}
