Forum Moderators: coopster & phranque

Message Too Old, No Replies

Trying to get meta tags

         

Regent

10:01 pm on Nov 19, 2004 (gmt 0)

10+ Year Member



Hi,

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.

Birdman

11:31 pm on Nov 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

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.

www.perldoc.com/perl5.6.1/lib/HTML/HeadParser.html

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