1HTML::HeadParser(3) User Contributed Perl Documentation HTML::HeadParser(3)
2
3
4
6 HTML::HeadParser - Parse <HEAD> section of a HTML document
7
9 require HTML::HeadParser;
10 $p = HTML::HeadParser->new;
11 $p->parse($text) and print "not finished";
12
13 $p->header('Title') # to access <title>....</title>
14 $p->header('Content-Base') # to access <base href="http://...">
15 $p->header('Foo') # to access <meta http-equiv="Foo" content="...">
16
18 The "HTML::HeadParser" is a specialized (and lightweight)
19 "HTML::Parser" that will only parse the <HEAD>...</HEAD> section of an
20 HTML document. The parse() method will return a FALSE value as soon as
21 some <BODY> element or body text are found, and should not be called
22 again after this.
23
24 Note that the "HTML::HeadParser" might get confused if raw undecoded
25 UTF-8 is passed to the parse() method. Make sure the strings are prop‐
26 erly decoded before passing them on.
27
28 The "HTML::HeadParser" keeps a reference to a header object, and the
29 parser will update this header object as the various elements of the
30 <HEAD> section of the HTML document are recognized. The following
31 header fields are affected:
32
33 Content-Base:
34 The Content-Base header is initialized from the <base href="...">
35 element.
36
37 Title:
38 The Title header is initialized from the <title>...</title> ele‐
39 ment.
40
41 Isindex:
42 The Isindex header will be added if there is a <isindex> element in
43 the <head>. The header value is initialized from the prompt
44 attribute if it is present. If no prompt attribute is given it
45 will have '?' as the value.
46
47 X-Meta-Foo:
48 All <meta> elements will initialize headers with the prefix
49 ""X-Meta-"" on the name. If the <meta> element contains a
50 "http-equiv" attribute, then it will be honored as the header name.
51
53 The following methods (in addition to those provided by the superclass)
54 are available:
55
56 $hp = HTML::HeadParser->new
57 $hp = HTML::HeadParser->new( $header )
58 The object constructor. The optional $header argument should be a
59 reference to an object that implement the header() and
60 push_header() methods as defined by the "HTTP::Headers" class.
61 Normally it will be of some class that isa or delegates to the
62 "HTTP::Headers" class.
63
64 If no $header is given "HTML::HeadParser" will create an
65 "HTTP::Header" object by itself (initially empty).
66
67 $hp->header;
68 Returns a reference to the header object.
69
70 $hp->header( $key )
71 Returns a header value. It is just a shorter way to write
72 "$hp->header->header($key)".
73
75 $h = HTTP::Headers->new;
76 $p = HTML::HeadParser->new($h);
77 $p->parse(<<EOT);
78 <title>Stupid example</title>
79 <base href="http://www.linpro.no/lwp/">
80 Normal text starts here.
81 EOT
82 undef $p;
83 print $h->title; # should print "Stupid example"
84
86 HTML::Parser, HTTP::Headers
87
88 The "HTTP::Headers" class is distributed as part of the libwww-perl
89 package. If you don't have that distribution installed you need to
90 provide the $header argument to the "HTML::HeadParser" constructor with
91 your own object that implements the documented protocol.
92
94 Copyright 1996-2001 Gisle Aas. All rights reserved.
95
96 This library is free software; you can redistribute it and/or modify it
97 under the same terms as Perl itself.
98
99
100
101perl v5.8.8 2006-04-26 HTML::HeadParser(3)