English 中文(简体)
如何用Perl修改本地HTML文件?
原标题:How can I modify a local HTML file in Perl?

有没有CPAN模块或代码片段可以在不使用regExp的情况下用于修改本地HTML文件?

我想做的事情:

  1. Change the start tag ( example : <div> to <div id="newtag"> )
  2. Add a tag before another ( example : </head> to <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.
最佳回答

如果您有HTML,而不是XHTML,那么您不希望使用XML解析器。

HTML::Parser是Perl的标准HTML解析器。几乎所有其他东西都建立在它之上。

HTML::TokeParser是HTML::Parser的替代接口。它根据需要返回内容,而不是将所有内容传递给回调。

HTML::TreeBuilder从HTML构建一个类似DOM的树,然后可以对其进行修改。

HTML::TreeBuilder::XPath通过XPath支持扩展了HTML::TreeBuilder。

HTML::Query使用类似jQuery的选择器扩展了HTML::TreeBuilder。

pQuery是另一个模块,它为HTML::TreeBuilder带来了更完整的jQuery兼容性。

问题回答

持续气道正压通气

简单的CPAN搜索返回

XPATH

听起来您似乎不熟悉XPath。这里有一个快速教程,让你熟悉。它不是Perl,但它将解释这些概念。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签