---
title: "html  xpath java parser"
author: "dikar"
date: "2011-12-23T14:01:33Z"
tags: []
categories: ["开源软件"]
slug: "html-xpath-java-parser"
draft: false
lastmod: "2011-12-23T14:05:31Z"
id: 1323074
url: "https://dikar.iteye.com/blog/1323074"
---

想爬取一个网页的生活数据使用，按照以前的方式是写正则来做了，但是面对页面经常变换的问题，而且有些正则不是那么一步到位就能写出，故希望能找到更合适的东西来解析html。

 

通过对比各种html的parser，最终选取了HtmlCleaner ，主要是他强大的支持xpath功能，以及对网页标签的容错性很好，api也很强大耐用。

 

htmlCleaner 官网

[http://htmlcleaner.sourceforge.net/javause.php](http://htmlcleaner.sourceforge.net/javause.php)

 

Using XPATH and HTML Cleaner to parse HTML / XML

[http://thinkandroid.wordpress.com/2010/01/05/using-xpath-and-html-cleaner-to-parse-html-xml/](http://thinkandroid.wordpress.com/2010/01/05/using-xpath-and-html-cleaner-to-parse-html-xml/)

 

xpath真是异常强大，这里给出参考文档

[http://www.w3schools.com/XPath/default.asp](http://www.w3schools.com/XPath/default.asp)

 

xpath有时写起来也是比较麻烦，所以找到了一个firefox的扩展可以很好的自动提取xpath

 

FirePath is a Firebug extension that adds a development tool to edit, inspect and generate XPath 1.0 expressions, CSS 3 selectors and JQuery selectors (Sizzle selector engine).

https://addons.mozilla.org/en-US/firefox/addon/firepath/

 

 

附：looking-for-a-java-html-parser-or-groovy

[http://www.wavyx.net/2009/01/13/looking-for-a-java-html-parser-or-groovy/](http://www.wavyx.net/2009/01/13/looking-for-a-java-html-parser-or-groovy/)