如何在java中使用xpath解析html数据

时间:2013-08-06 10:15:11

标签: java html xpath html-parsing

我正在编写一个java代码,我使用xpath表达式从特定网址中提取特定数据。

执行我的代码后,我没有得到理想的结果。

这是我的代码:

    try{
     URL oracle = new URL();  
URLConnection yc = oracle.openConnection();  
InputStream is = yc.getInputStream();  
is = oracle.openStream();  
Tidy tidy = new Tidy();  
tidy.setQuiet(true);  
tidy.setShowWarnings(false);  
Document tidyDOM = tidy.parseDOM(is, null);  
XPathFactory xPathFactory = XPathFactory.newInstance();  
XPath xPath = xPathFactory.newXPath();  
XPathExpression xPathExpression = xPath.compile("");  
Object result = xPathExpression.evaluate(tidyDOM,XPathConstants.NODESET);  
System.out.println(result.toString());
}catch(Exception e){
    System.out.println("error");


}

输出:

       com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList@7e97d1ff

我想要这个网址的产品价格:http://www.flipkart.com/d-link-8-port-10-100m-unmanaged-standalone-switch-network/p/itmdffym2nhwyzvz

我在我的代码中使用的xpath是:/ html / body / div / div [2] / div / div / div [3] / div / div / div [3] / div [2] / div / DIV / DIV / DIV /跨度

谁能告诉我我做错了什么?

0 个答案:

没有答案