Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting Display:None With Jsoup

Tags:

java

jsoup

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?

like image 471
akshayb Avatar asked Apr 13 '26 19:04

akshayb


1 Answers

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

like image 138
cmbaxter Avatar answered Apr 16 '26 11:04

cmbaxter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!