//nekohtml结合xpath用法
DOMParser parser = new DOMParser();
try {
//设置网页的默认编码
parser.setProperty("http://cyberneko.org/html/properties/default-encoding","gb2312");
/*The Xerces HTML DOM implementation does not support namespaces
and cannot represent XHTML documents with namespace information.
Therefore, in order to use the default HTML DOM implementation with NekoHTML's
DOMParser to parse XHTML documents, you must turn off namespace processing.*/
parser.setFeature("http://xml.org/sax/features/namespaces", false);
String strURL = "http://product.dangdang.com/product.aspx?product_id=9317290";
BufferedReader in = new BufferedReader(
new InputStreamReader(
new URL(strURL).openStream()));
parser.parse(new InputSource(in));
in.close();
} catch (Exception e) {
e.printStackTrace();
}
Document doc = parser.getDocument();
// tags should be in upper case
String productsXpath = "/HTML/BODY/DIV[2]/DIV[4]/DIV[2]/DIV/DIV[3]/UL[@class]/LI[9]";
NodeList products;
try {
products = XPathAPI.selectNodeList(doc, productsXpath);
System.out.println("found: " + products.getLength());
Node node = null;
for(int i=0; i< products.getLength();i++)
{
node = products.item(i);
System.out.println( i + ":\n" + node.getTextContent());
}
}catch (TransformerException e) {
e.printStackTrace();
}
分享到:
相关推荐
NekoHTML的相关用法以及代码包,以及详细的用法和实例。。。。。
NekoHTML技术预研说明,如何进行HTML页面解析,网页信息抽取
NekoHTML is written using the Xerces Native Interface (XNI) that is the foundation of the Xerces2 implementation. This enables you to use the NekoHTML parser with existing XNI tools without ...
NULL 博文链接:https://thrillerzw.iteye.com/blog/1924229
html解析器nekohtml-1.9.13.zip
NekoHTML学习笔记.doc
NekoHTML是一个简单地HTML扫描器和标签补偿器(tag balancer) ,使得程序能解析HTML文档并用标准的XML接口来访问其中的信息。...NekoHTML的开发使用了Xerces Native Interface (XNI),后者是Xerces2的实现基础。
NekoHTML是一个Java语言的 HTML扫描器和标签补全器(tag balancer) ,使得程序能解析HTML文档并用标准的XML接口来访问其中的信息。这个解析器能够扫描HTML文件并“修正”许多作者(人或机器)在编写HTML文档 过程中常...
NeKoHTML:用于java的html编辑。此文件是NeKoHTML V1.9.21版本的Java包合集。
nekohtml.jar 解析html的jar包 非常的实用
nekohtml.jar nekohtmlSamples.jar
NekoHTML是一个简单地HTML扫描器和标签补偿器(tag balancer) ,使得程序能解析HTML文档并用标准的XML接口来访问其中的信息。这个解析器能投扫描HTML文件并“修正”许多作者(人或机器)在编写HTML文档过程中常犯的...
nekohtml-1.9.14源码及jar包
采用nekohtml补全html到xhtml,结合dom,运用dom4j,支持xpath,强大的网抓工具!
NULL 博文链接:https://rensanning.iteye.com/blog/1551831
nekoHtml 1.9.19 加 source 源码 html分析jar
nekohtml-1.9.18_
nekohtml-0.9.4.jar nekohtml-0.9.4.jar nekohtml-0.9.4.jar
需要的可以下载这个jar包,不要任何积分哦……
NULL 博文链接:https://tianhewulei.iteye.com/blog/629672