简体   繁体   English

如何在Perl中修改本地HTML文件?

[英]How can I modify a local HTML file in Perl?

Is there a CPAN module or code snippet that I can use to modify local HTML files without using a regExp? 是否有CPAN模块或代码段,可用于在不使用regExp的情况下修改本地HTML文件?

What I want to do : 我想做的事 :

  1. Change the start tag ( example : <div> to <div id="newtag"> ) 更改开始标记(例如: <div><div id="newtag">
  2. Add a tag before another ( example : </head> to <script type="text/javascript"> ...</script></head> 在另一个标签之前添加标签(例如: </head><script type="text/javascript"> ...</script></head>
  3. Remove tags 移除标签
  4. Read the content of a given tag. 读取给定标签的内容。 (<- ok this can be done with an XML / HTML parser. (<-好的,可以使用XML / HTML解析器来完成。

If you have HTML, and not XHTML, then you don't want to be using an XML parser. 如果您拥有HTML,而没有XHTML,则您不想使用XML解析器。

HTML::Parser is the standard HTML parser for Perl. HTML :: Parser是Perl的标准HTML解析器。 Pretty much everything else is built on top of it. 几乎所有其他内容都建立在其之上。

HTML::TokeParser is an alternative interface to HTML::Parser. HTML :: TokeParser是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从HTML构建类似DOM的树,然后可以对其进行修改。

HTML::TreeBuilder::XPath extends HTML::TreeBuilder with XPath support. HTML :: TreeBuilder :: XPath扩展了具有XPath支持的HTML :: TreeBuilder。

HTML::Query extends HTML::TreeBuilder with jQuery-like selectors. HTML :: Query通过类似jQuery的选择器扩展了HTML :: TreeBuilder。

pQuery is another module that brings more complete jQuery compatibility to HTML::TreeBuilder. pQuery是另一个模块,它为HTML :: TreeBuilder提供了更完整的jQuery兼容性。

CPAN CPAN

A simple CPAN search returns 一个简单的CPAN搜索返回

XPATH XPATH

It sounds like you are not familiar with XPath. 听起来您不熟悉XPath。 Here is a quick tutorial to get you familiar. 这是一个使您熟悉的快速教程。 Its not Perl but it will explain the concepts. 它不是Perl,但将解释概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM