Parsing html with Jsoup and removing spans with certain style
android, html, java, jsoup
Solution
If you want to remove those spans completely based on the style attribute, try this code:
String html = "<span style=\"display:none\">&0000000000000217000000</span>";
html += "<span style=\"display:none\">&1111111111111111111111111</span>";
html += "<p>Test paragraph should not be removed</p>";
Document doc = Jsoup.parse(html);
doc.select("span[style*=display:none]").remove();
System.out.println(doc);
Here is the output:
<html>
<head></head>
<body>
<p>Test paragraph should not be removed</p>
</body>
</html>
Problem
I'm writing an app for a friend but I ran into a problem, the website has these ``` <span style="display:none">&0000000000000217000000</span> ``` And we have no idea even what they are, but I need them removed because my app is outputting their value. Is there any way I can check to see if this is in the Elements and remove it? I have a for-each loop parsing however I cant figure out how to effectively remove this element. thanks