Java 如何搜索指定属性不存在的元素';不存在,在jsoup中?
我需要找到我指定的属性不存在的元素。比如:Java 如何搜索指定属性不存在的元素';不存在,在jsoup中?,java,jsoup,Java,Jsoup,我需要找到我指定的属性不存在的元素。比如: Doc.select( "some_tag[attribute=""]" ); 或者类似的东西,比如: Doc.select( "some_tag[!attribute]" ); 正如我所知,本机jsoup不支持xpath,因此这是不可能的 也许有一些技巧可以做到这一点?解决这个问题的一种方法是使用:not选择器。下面是选择所有div而不使用id的示例 String url = "http://stackoverflow.com/questions
Doc.select( "some_tag[attribute=""]" );
或者类似的东西,比如:
Doc.select( "some_tag[!attribute]" );
正如我所知,本机jsoup不支持xpath,因此这是不可能的
也许有一些技巧可以做到这一点?解决这个问题的一种方法是使用
:not
选择器。下面是选择所有div
而不使用id
的示例
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"));
}