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.

 

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