日期:2014-05-17  浏览次数:20651 次

htmlcleaner 使用示例.

原文出处:http://blog.chenlb.com/2008/11/htmlcleaner-use-demo.html

<!-- google_ad_section_start -->

编程的时候,有时数据源从html来。那就要对html分析提取数据。好在java社区里有好有相关库来解析html,经使用比较:个人 觉得 htmlcleaner 比 htmlparser 好用。htmlcleaner 的 xpath特好用。也可能我对htmlparser不熟悉。

htmlcleaner 下载地址:htmlcleaner2_1.jar 源码下载:htmlcleaner2_1-all.zip

写一个测试用的html文件:html-clean-demo.html

  1. <!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " > ??
  2. < html ? xmlns = "http://www.w3.org/1999/xhtml " ? xml:lang = "zh-CN" ? dir = "ltr" > ??
  3. < head > ??
  4. ????< meta ? http-equiv = "Content-Type" ? content = "text/html;?charset=GBK" /> ??
  5. ????< meta ? http-equiv = "Content-Language" ? content = "zh-CN" /> ??
  6. ????< title > html?clean?demo </ title > ??
  7. </ head > ??
  8. < body > ??
  9. < div ? class = "d_1" > ??
  10. ????< ul > ??
  11. ????????< li > bar </ li > ??
  12. ????????< li > foo </ li > ??
  13. ????????< li > gzz </ li > ??
  14. ????</ ul > ??