How to select an element with an empty class using Jsoup
I would use the cge regex li[class~=^$] selector:
String html= "<li class=\"\" > </li>" + "<li class= > </li>" + "<li class > </li>" + "<li > </li>" + "<li class=\"test\" > </li>"; Document doc = Jsoup.parse(html,""); Elements liWithClassButNoName = doc.select("li[class~=^$]"); for (Element li:liWithClassButNoName){ System.out.println("li = "+ li); } leads to this result (only the first match is 3 lisa):
li = <li class=""> </li> li = <li class> </li> li = <li class> </li> Explanation:
~= means regular expression and ^$ searches for an empty string
Jsoup will remove = in the second example, li element <li class= > . The regular expression also matches essentially with a nonexistent string, so if you need to filter them, you can go with the solution given by @TDG.