0

我正在使用带有 java 的 TagSoup 来提取一些数据,但是某些 XPATH 不起作用,我只是得到空结果

  FileReader frInHtml = new FileReader("doc.html");
  BufferedReader brInHtml = new BufferedReader(frInHtml);

  SAXBuilder saxBuilder = new SAXBuilder("org.ccil.cowan.tagsoup.Parser");
   org.jdom.Document jdomDocument = saxBuilder.build(brInHtml);

 // This is working                                
 XPath xpath = XPath.newInstance("/ns:html[1]/ns:body/ns:div[@class='content']/ns:table/ns:tr/ns:td/ns:h1");

// All 3 lines below didn't work , tried them 1 at a time 
  XPath xpath = XPath.newInstance("/ns:html/ns:body/ns:div[7]/ns:table/ns:tbody/ns:tr/ns:td/ns:h1");
  XPath xpath = XPath.newInstance("//html//body//div[7]//table//tbody//tr//td//h1");
  XPath xpath = XPath.newInstance("/html/body/div[7]/table/tbody/tr/td/h1");                               

   xpath.addNamespace("ns", "http://www.w3.org/1999/xhtml");
4

1 回答 1

1

要对此进行调试,您需要查看 TagSoup 生成的“等效 XML”。为了让我们帮助您,您需要向我们展示等效的 XML。

于 2012-01-17T16:43:14.427 回答