I think you can use the JSOUP CSS selector p:not([^]) , which will select any p that does not match an attribute starting with something,
String html = "<div id=\"intro\">" + "<h1 class=\"some class\">" + "<p id=\"some_id\">" + "Some text 1" + "</p>" + "<p name=\"some_name\">" + "Some text A" + "</p>" + "<p data>" + "Some text B" + "</p>" +"<p>" + "Some text 2" +"</p>" +"</div> "; Document doc = Jsoup.parse(html); Elements els = doc.select("p:not([^])"); for (Element el:els){ System.out.println(el.text()); }
the above example will only print
Some text 2
because only this p element has no attributes.
Note that the p[^] selector will select all p elements that have an attribute.
source share