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