Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何搜索指定属性不存在的元素';不存在,在jsoup中?_Java_Jsoup - Fatal编程技术网

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"));
}