| 1 |
Hi, |
| 2 |
|
| 3 |
This is the HTML::SimpleParse module. It is a bare-bones HTML parser, |
| 4 |
similar to HTML::Parser, but with a couple important distinctions: |
| 5 |
|
| 6 |
|
| 7 |
First, HTML::Parser knows which tags can contain other tags, which start |
| 8 |
tags have corresponding end tags, which tags can exist only in the <HEAD> |
| 9 |
portion of the document, and so forth. HTML::SimpleParse does not know any |
| 10 |
of these things. It just finds tags and text in the HTML you give it, it |
| 11 |
does not care about the specific content of these tags (though it does |
| 12 |
distiguish between different _types_ of tags, such as comments, starting |
| 13 |
tags like <b>, ending tags like </b>, and so on). |
| 14 |
|
| 15 |
Second, HTML::SimpleParse does not create a hierarchical tree of HTML |
| 16 |
content, but rather a simple linear list. It does not pay any attention to |
| 17 |
balancing start tags with corresponding end tags, or which pairs of tags are |
| 18 |
inside other pairs of tags. |
| 19 |
|
| 20 |
Because of these characteristics, you can make a very effective HTML filter |
| 21 |
by sub-classing HTML::SimpleParse. For example, to remove all comments: |
| 22 |
|
| 23 |
package NoComment; |
| 24 |
use HTML::SimpleParse; |
| 25 |
@ISA = qw(HTML::SimpleParse); |
| 26 |
sub output_comment {} |
| 27 |
|
| 28 |
package main; |
| 29 |
NoComment->new($some_html)->output; |
| 30 |
|
| 31 |
|
| 32 |
For more specific information, please see the documentation inside |
| 33 |
SimpleParse.pm, by doing "pod2txt SimpleParse.pm", or "perldoc |
| 34 |
HTML::SimpleParse" once you've installed the module. |
| 35 |
|
| 36 |
To install the module, do the usual: |
| 37 |
|
| 38 |
perl Makefile.PL |
| 39 |
make |
| 40 |
make test |
| 41 |
make install |
| 42 |
|
| 43 |
-Ken Williams |