programming-examples/perl/Network/Extract link from a web page.pl
2019-11-15 12:59:38 +01:00

26 lines
421 B
Perl

use LWP::Simple;
use HTML::LinkExtor;
$html = get("http://www.java2s.com");
$link_extor = HTML::LinkExtor->new(\&handle_links);
$link_extor->parse($html);
sub handle_links
{
($tag, %links) = @_;
if ($tag eq 'a') {
foreach $key (keys %links) {
if ($key eq 'href') {
print "Found a hyperlink to $links{$key}.\n";
}
}
}
}