Reputation: 113
Is there a CPAN module or code snippet that I can use to modify local HTML files without using a regExp?
What I want to do :
<div>
to <div id="newtag">
)</head>
to <script type="text/javascript"> ...</script></head>
Upvotes: 0
Views: 748
Reputation: 62109
If you have HTML, and not XHTML, then you don't want to be using an XML parser.
HTML::Parser is the standard HTML parser for Perl. Pretty much everything else is built on top of it.
HTML::TokeParser is an alternative interface to HTML::Parser. It returns things on demand instead of passing everything to callbacks.
HTML::TreeBuilder builds a DOM-like tree from the HTML, which you can then modify.
HTML::TreeBuilder::XPath extends HTML::TreeBuilder with XPath support.
HTML::Query extends HTML::TreeBuilder with jQuery-like selectors.
pQuery is another module that brings more complete jQuery compatibility to HTML::TreeBuilder.
Upvotes: 6
Reputation:
CPAN
A simple CPAN search returns
XPATH
It sounds like you are not familiar with XPath. Here is a quick tutorial to get you familiar. Its not Perl but it will explain the concepts.
Upvotes: 1