HTML::HeadParser - Parse <HEAD> section of a HTML document
require HTML::HeadParser; $p = HTML::HeadParser->new; $p->parse($text) and print "not finished"; $p->header('Title') # to access <title>....</title> $p->header('Content-Base') # to access <base href="http://..."> $p->header('Foo') # to access <meta http-equiv="Foo" content="...">
The HTML::HeadParser is a specialized (and lightweight) HTML::Parser that will only parse the <HEAD>...</HEAD> section of a HTML document. The parse() and parse_file() methods will return a FALSE value as soon as a <BODY> element is found, and should not be called again after this.
The HTML::HeadParser constructor takes a HTTP::Headers object reference as argument. The parser will update this header object as the various head elements are recognized.
The following header fields are initialized from elements found in the <head> section of a HTML document:
The Content-Base header is initialized from the <base href="..."> element.
The Title header is initialized from the <title>...</title> element.
The Isindex header will be added if there is a <isindex> element in the <head>. The header value is initialized from the prompt attribute if it is present.
All <meta> elements will initialize headers with the prefix "X-Meta-". If the element contains a http-equiv attribute, then it will be honored as the header name.
$h = HTTP::Headers->new; $p = HTML::HeadParser->new($h); $p->parse(<<EOT); <title>Stupid example</title> <base href="http://www.sn.no/libwww-perl/"> Normal text starts here. EOT undef $p; print $h->title; # should print "Stupid example"
HTML::Parser, HTTP::Headers
Copyright 1996 Gisle Aas. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Gisle Aas <aas@sn.no>
To install LWP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm LWP
CPAN shell
perl -MCPAN -e shell install LWP
For more information on module installation, please visit the detailed CPAN module installation guide.