gpt4 book ai didi

java - org.jsoup.select.Selector$SelectorParseException : Could not parse query

转载 作者:行者123 更新时间:2023-12-02 19:34:05 26 4
gpt4 key购买 nike

我正在使用 Xsoup。

这是代码:

private void updateSeed(Document document) {
mappingParser
.setSeed(Xsoup.compile("//div[@class='pgCell'][last()]/a/@href")
.evaluate(document).get());
}

当我执行上一个函数时,出现以下异常:

Exception in thread "main" org.jsoup.select.Selector$SelectorParseException: Could not parse query 'div[@class='pgCell'][last()]': unexpected token at 'last()'
at us.codecraft.xsoup.xevaluator.XPathParser.byFunction(XPathParser.java:225)
at us.codecraft.xsoup.xevaluator.XPathParser.consumePredicates(XPathParser.java:202)
at us.codecraft.xsoup.xevaluator.XPathParser.findElements(XPathParser.java:138)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:51)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:375)
at us.codecraft.xsoup.xevaluator.XPathParser.combinator(XPathParser.java:85)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:49)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:375)
at us.codecraft.xsoup.Xsoup.compile(Xsoup.java:27)
at com.qannoufit.test.CrawlerController.updateSeed(CrawlerController.java:102)
at com.qannoufit.test.CrawlerController.populateShouldParse(CrawlerController.java:91)
at com.qannoufit.test.CrawlerController.startCrawling(CrawlerController.java:60)
at com.qannoufit.test.Main.main(Main.java:12)

最佳答案

尝试使用 CSS 选择器。初始 xPath 查询可以翻译如下:

div.pgCell:last-of-type > a

获得 anchor 后,即可获取其 href。

private void updateSeed(Document document) {
Element anchor = document.select("div.pgCell:last-of-type > a").first();
if (anchor==null) {
// Anchor not found, handle error here...
}

mappingParser.setSeed(anchor.absUrl("href"));
}

关于java - org.jsoup.select.Selector$SelectorParseException : Could not parse query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30401656/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com