Use Jsoup to select an HTML element with no class

我怕爱的太早我们不能终老 提交于 2019-12-05 09:19:49
Elements ps = body.select("p:not(.random_class_name)");

You can use the pseudo selector :not

If the class name is not known, you still can use a similar expression:

Elements ps = body.select("p:not([class])");

In the second example I use the attribute selector [], in the first the normal syntax for classes.

See the Jsoup docu about css selectors

Document doc = Jsoup.parse(htmlValue);
    Elements pElements = doc.select("p");         
    for (Element element : pElements) {
        String class = element.attr("class");
        if(class == null){
            //.....
        }else{
             //.....
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!