zhegexiaohuozi/JsoupXpath

为什么不支持从根节点开始的Xpath

hellokitty-v opened this issue · 0 comments

  1. 使用的表达式与使用场景,确保能够复现(What did you do , If possible, provide a recipe for reproducing the error.)?
    如果Xpath是 [/html开头的都会报错,
    测试代码:
    String xpath = "/html";
    String html = FileUtils.readFileToString(new File("tmp/test.html"), Charsets.UTF_8);
    JXDocument doc = JXDocument.create(html);
    System.out.println(doc.selNOne(xpath));

  2. 期望看到什么(What did you expect to see)?

支持获取/html开头的绝对路径Xpath,对于上例就是整个文档

  1. JsoupXpath给出的结果是什么(What did you see instead)?

报错异常:

Exception in thread "main" org.seimicrawler.xpath.exception.XpathSyntaxErrorException: Please check the syntax of your xpath expr or commit a InputMismatchException:
at org.seimicrawler.xpath.JXDocument.selN(JXDocument.java:136)
at org.seimicrawler.xpath.JXDocument.selNOne(JXDocument.java:154)
at com.run.website.TestXpath.main(TestXpath.java:20)
Caused by: org.antlr.v4.runtime.misc.ParseCancellationException
at org.seimicrawler.xpath.exception.DoFailOnErrorHandler.recoverInline(DoFailOnErrorHandler.java:32)
at org.antlr.v4.runtime.Parser.match(Parser.java:206)
at org.seimicrawler.xpath.antlr.XpathParser.nodeTest(XpathParser.java:585)
at org.seimicrawler.xpath.antlr.XpathParser.step(XpathParser.java:428)
at org.seimicrawler.xpath.antlr.XpathParser.relativeLocationPath(XpathParser.java:335)
at org.seimicrawler.xpath.antlr.XpathParser.absoluteLocationPathNoroot(XpathParser.java:278)
at org.seimicrawler.xpath.antlr.XpathParser.locationPath(XpathParser.java:215)
at org.seimicrawler.xpath.antlr.XpathParser.pathExprNoRoot(XpathParser.java:1070)
at org.seimicrawler.xpath.antlr.XpathParser.unionExprNoRoot(XpathParser.java:987)
at org.seimicrawler.xpath.antlr.XpathParser.unaryExprNoRoot(XpathParser.java:1693)
at org.seimicrawler.xpath.antlr.XpathParser.multiplicativeExpr(XpathParser.java:1615)
at org.seimicrawler.xpath.antlr.XpathParser.additiveExpr(XpathParser.java:1538)
at org.seimicrawler.xpath.antlr.XpathParser.relationalExpr(XpathParser.java:1456)
at org.seimicrawler.xpath.antlr.XpathParser.equalityExpr(XpathParser.java:1350)
at org.seimicrawler.xpath.antlr.XpathParser.andExpr(XpathParser.java:1277)
at org.seimicrawler.xpath.antlr.XpathParser.orExpr(XpathParser.java:1213)
at org.seimicrawler.xpath.antlr.XpathParser.expr(XpathParser.java:750)
at org.seimicrawler.xpath.antlr.XpathParser.main(XpathParser.java:149)
at org.seimicrawler.xpath.JXDocument.selN(JXDocument.java:93)
... 2 more
Caused by: org.antlr.v4.runtime.InputMismatchException
at org.seimicrawler.xpath.exception.DoFailOnErrorHandler.recoverInline(DoFailOnErrorHandler.java:28)

从调用代码上看使用了absoluteLocationPathNoroot,从字面意思看是使用了无根的绝对路径,是说不支持根节点吗,这样做的原因是什么

  1. 当前使用的版本(What version of JsoupXpath are you using)?

2.5.1