gpt4 book ai didi

java - 如何在jsoup中搜索指定属性不存在的元素?

转载 作者:行者123 更新时间:2023-12-02 08:11:24 25 4
gpt4 key购买 nike

我需要查找我指定的属性不存在的元素。像这样的东西:

Doc.select( "some_tag[attribute=""]" );

或者类似的东西:

Doc.select( "some_tag[!attribute]" );

据我所知,jsoup 本身不支持 xpath,所以这是不可能的。

也许有一些技巧可以实现这一点?

最佳答案

解决此问题的一种方法是使用 :not 选择器。下面是选择所有没有 iddiv 的示例。

String url = "http://stackoverflow.com/questions/7377316/how-to-search-for-elements-where-specified-attribute-doesnt-exist-in-jsoup";
Document doc = Jsoup.connect(url).get();
//Select all divs without id
Elements divsWithoutid = doc.select("div:not([id])");
for (Element e : divsWithoutid) {
//See ma, no id
System.out.println("id = " + e.attr("id"));
}

关于java - 如何在jsoup中搜索指定属性不存在的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7377316/

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