++ed by:

81 PAUSE users
59 non-PAUSE users.

Gisle Aas


parse_html - Parse HTML text

parse_htmlfile - Parse HTML text from file


 use HTML::Parse;
 $h = parse_htmlfile("test.html");
 print $h->dump;
 $h = parse_html("<p>Some more <i>italic</i> text", $h);

 print parse_htmlfile("index.html")->asHTML;  # tidy up markup in a file


This module provides functions to parse HTML text. The result of the parsing is a HTML syntax tree with HTML::Element objects as nodes. Check out HTML::Element for details of methods available to access the syntax tree.

The parser currently understands HTML 2.0 markup + tables + some Netscape extentions.

Entites in all text content and attribute values will be expanded by the parser.

You must delete the parse tree explicitly to free the memory assosiated with it before the perl interpreter terminates. The reason for this is that the parse tree contains circular references (parents have references to their children and children have a reference to their parent).

The following variables control how parsing takes place:


Setting this variable to true will instruct the parser to try to deduce implicit elements and implicit end tags. If this variable is false you get a parse tree that just reflects the text as it stands. Might be useful for quick & dirty parsing. Default is true.

Implicit elements have the implicit() attribute set.


This variable contols whether unknow tags should be represented as elements in the parse tree. Default is true.


Do not represent the text content of elements. This saves space if all you want is to examine the structure of the document. Default is false.


HTML::Element, HTML::Entities


Copyright (c) 1995 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@oslonett.no>