I need to grab a web page then print the title and meta description. I've already been able to print out the title using the following:
my $h = HTTP::Headers->new;
my $p = HTML::HeadParser->new($h);
$p->parse($html) and print "not finished";
$p->header('Title');
print $h->title;
print $h->title;
But I can't figure out how to print out the meta description using HTTP::Headers and HTML::HeadParser. Is there any way to do this using these packages? I don't want to bother with regular expressions.
Thanks.
X-Meta-Foo:
All <meta> elements will initialize headers with the prefix "X-Meta-" on the name. If the <meta> element contains a http-equiv attribute, then it will be honored as the header name.
my $h = HTTP::Headers->new;
my $p = HTML::HeadParser->new($h);
$p->parse($html) and print "not finished";
$p->header('Title');
$p->header('X-Meta-description');
print $h->title;
print $h->x-meta-description;
Now, I'm not quite sure on the exact syntax, but this should get you headed in the right direction.
regards