HtmlCleaner,Html解析专家

通常互联网上的HTML页面都是不规则的,非结构化的页面。如果我们需要访问或者抽取里面的内容的话,我们需要分析HTML页面,去除垃圾。
而最近新发布的 HtmlCleaner 就是这样一个工具. 能够帮助我们将HTML 文档 转化为结构化的XML文档。虽然目前已经有了类似这样的工具,但是HtmlCleaner 能够完成几乎所有的HTML转换,而且不到30k,这是他们值得称道的地方。

HtmlCleaner是一个开源的Html文档解析器。HtmlCleaner能够安全的解析和转换web上的HTML到标准的XML,重新排序每个元素,然后生成结构良好(Well-Formed)XML文档。默认它遵循的规则是类似于大部份web浏览器为创文档对象模型所使用的规则。然后,用户可以提供自定义tag和规则组来进行过滤和匹配。它被设计的小,快速,灵活而且独立。HtmlCleaner也可用在Java代码中,当命令行工具或Ant任务。 解析后编程轻量级文档对象,能够很容易的被转换到DOM或者JDom标准文档,或者通过各种方式(压缩,打印)连续输出XML

新版本的重要功能更新包括:
1.HtmlCleaner的文档对象模型现在拥有了一些函数,处理节点和属性,所以现在在序列化之前搜索或者编辑是非常容易的。
2.提供基本HtmlCleaner DOMXPath支持
3.使用XML配置温江让创建定制tag变得更加容易
4.修复多个bug以及API改进

更多详细信息:HTML Parser工具HtmlCleaner 2.0发布

 

上文作者:javaread.com

HtmlCleaner is open-source HTML parser written in Java.

HTML found on Web is usually dirty, ill-formed and unsuitable for further processing.

For any serious consumption of such documents, it is necessary to first clean up the mess and bring the order to tags,

attributes and ordinary text.

For the given HTML document, HtmlCleaner reorders individual elements and produces well-formed XML.

By default, it follows similar rules that the most of web browsers use in order to create Document Object Model.

However, user may provide custom tag and rule set for tag filtering and balancing.

Here is a typical example - improperly structured HTML containing unclosed tags and missing quotes:

   

After putting it through HtmlCleaner, XML similar to the following is coming out:

    

HtmlCleaner can be used in java code, as command line tool or as Ant task.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章