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 40 41 42 43 44
| #!/usr/bin/perl
use strict;
use warnings;
use HTML::Parser;
my $page = "C:\\Perl\\web.htm";
# création de mon parser
my $parser = HTML::Parser->new();
# définition des mes evenements
$parser->handler( text => \&text, "dtext" );
$parser->handler( start => \&start, "tagname,attr" );
$parser->handler( end => \&end, "tagname" );
$parser->parse($page);
print get_data();
{
my $in;
my @data;
sub start {
my ($tag, $attr) = @_;
$in++ if $tag eq '<b>' and $attr->{class} eq '*';
}
sub end {
my ($tag) = @_;
$in-- if $tag eq '<b>' and $in;
}
sub text {
my ($text) = @_;
push @data, $text if $in;
}
sub get_data {
return @data;
}
}
exit; |
Partager