I need to do some parse some data off webpages. How do I extract text between tags using HTML::Parser?
Consider the following sample code:
#!/usr/bin/perl
use strict;
use warnings;
use HTML::Parser;
use Data::Dumper;
my $find_title = HTML::Parser->new(
api_version => 3,
start_h => [
sub {
my ($tag, $attr) = @_;
print Dumper \@_;
},
'tag'
],
);
my $html = join '',
"<html><head><title>Extract me!</title></head><body>",
(map { qq(<a href="http://$_.com">$_</a>) } qw/foo bar baz/),
"</body></html>";
$find_title->report_tags('title');
$find_title->parse($html);
How do I fix this so I can extract the title? This only extracts the tag.