#! /usr/bin/perl use strict; use warnings; use Encode; use HTML::Parser; use LWP::UserAgent; my @links; my $url = "http://google.de/"; my $ua = LWP::UserAgent->new(); my $response = $ua->get($url); my $inhalt = $response->decoded_content; my $p = HTML::Parser->new(); $p->handler(start => \&start_handler,"self,tagname,attr"); $p->parse($inhalt); foreach my $link (@links){ my $linkziel = $link->[0]; if (defined($linkziel)){ print $linkziel."\n"; if($linkziel =~ ("/http/i")){ print "Linktext: ",$link->[1],"\tURL: ",$link->[0],"\n"; } } } sub start_handler{ my ($self, $tag, $attr) = @_; return if($tag ne 'a'); my ($link) = $attr->{href}; my $text; $self->handler(text => sub{$text = shift;},"dtext"); $self->handler(end => sub { my ($tag) = @_; if ($tag eq 'a'){ push(@links,[$link,$text]) } },"tagname"); }