1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #!/usr/bin/perl -w
use strict;
use LWP::Simple;
use HTML::Parser;
my $tag = 'b';
my $source = shift || 'http://developpez.com/';
my $page = get($source)
or die "Couldn't get $source: $!\n";
my $parser = HTML::Parser->new( api_version => 3,
start_h => [\&start,"tagname"],
text_h => [\&text,"text"],
end_h => [\&end,"tagname"],
);
my $intag_flag = 0;
my @intags;
sub start {
my ($tagname) = @_;
$intag_flag = 1 if $tagname eq $tag;
}
sub text {
my ($text) = @_;
if ($intag_flag) {
push @intags, $text;
}
}
sub end {
my ($tagname) = @_;
$intag_flag = 0 if ($tagname eq $tag);
}
$parser->parse($page);
$parser->eof;
print map {"$_\n"} @intags; |
Partager