I am practicing with JSoup to see the possibilities this amazing parser can do. There is one thing I am unable to resolve :
I need to remove tags with display none attribute. One obvious way is to use select :
doc.select("*[style=display:none]").remove();
But this doesn't apply to all cases. Sometimes, in style tag, there are more than one property, like style="display:none,width...." and someytimes, there are spaces, colons etc like style="display: none;".
I tried to solve this by applying :
if(!doc.getElementsByAttributeValueContaining("style", "display").isEmpty()){
if(!doc.getElementsByAttributeValueContaining("style", "none").isEmpty()){
// Not sure what to remove here.
}
}
What should be the approach to get this done?
You could try the valContaining construct for your selector like so:
doc.select("*[style*=display:none]").remove();
If this does not match what you want, try checking out the documentation here for more options:
http://jsoup.org/apidocs/org/jsoup/select/Selector.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With