문제

I have this content :

    "content":"<p style="text-align: justify;"><strong>Spotify je známy prehrávač, ktorý prehráva hudbu z internetu – nepotrebujete nič sťahovať. Dnes bola na aplikáciu vydaná nová aktualizácia, ktorá prináša užitočné zmeny.</strong></p> 
<p style="text-align: justify;"><span id="more-4569"></span></p> <p style="text-align: justify;">Užívateľov tejto aplikácie poteší nový tmavý design, ktorý je na oko celkom pekný. Vývojári ním chceli najmä zvýrazniť obsah a použiť moderné prvky. Ja síce túto aplikáciu veľmi nepoužívam, no som veľmi rád, že sa rozhodli pre niečo tmavšie, keďže mi ten biely design v tme ťahal oči.</p> <style type='text/css'> #gallery-1 { margin: auto; } #gallery-1 .gallery-item { float: left; margin-top: 10px; text-align: center; width: 50%; } #gallery-1 img { border: 2px solid #cfcfcf; } #gallery-1 .gallery-caption { margin-left: 0; } /* see gallery_shortcode() in wp-includes/media.php */ </style> <div id='gallery-1' class='gallery galleryid-4569 gallery-columns-2 gallery-size-thumbnail'><dl class='gallery-item'> <dt class='gallery-icon portrait'> <a href='http://www.androidaci.net/wp-content/uploads/nexusae0_android3.png'><img width="150" height="150" src="http://www.androidaci.net/wp-content/uploads/nexusae0_android3-150x150.png" class="attachment-thumbnail" alt="nexusae0_android3" /></a> </dt></dl><dl class='gallery-item'> <dt class='gallery-icon portrait'> <a href='http://www.androidaci.net/wp-content/uploads/nexusae0_android2.png'><img width="150" height="150" src="http://www.androidaci.net/wp-content/uploads/nexusae0_android2-150x150.png" class="attachment-thumbnail" alt="nexusae0_android2" /></a> </dt></dl><br style="clear: both" /> </div> <p>Ďalšia nová vec je sekcia “Your Music”, ktorá slúži na vytvorenie vlastného playlistu (zoznamu skladieb). Poslednou novinkou v tejto aktualizácií je zlepšenie vyhľadávania podľa lokalizácie a relevancie.</p> <style type='text/css'> #gallery-2 { margin: auto; } #gallery-2 .gallery-item { float: left; margin-top: 10px; text-align: center; width: 50%; } #gallery-2 img { border: 2px solid #cfcfcf; } #gallery-2 .gallery-caption { margin-left: 0; } /* see gallery_shortcode() in wp-includes/media.php */ </style> <div id='gallery-2' class='gallery galleryid-4569 gallery-columns-2 gallery-size-thumbnail'><dl class='gallery-item'> <dt class='gallery-icon portrait'> <a href='http://www.androidaci.net/wp-content/uploads/nexusae0_andorid4.png'><img width="150" height="150" src="http://www.androidaci.net/wp-content/uploads/nexusae0_andorid4-150x150.png" class="attachment-thumbnail" alt="nexusae0_andorid4" /></a> </dt></dl><dl class='gallery-item'> <dt class='gallery-icon portrait'> <a href='http://www.androidaci.net/wp-content/uploads/nexusae0_android1.png'><img width="150" height="150" src="http://www.androidaci.net/wp-content/uploads/nexusae0_android1-150x150.png" class="attachment-thumbnail" alt="nexusae0_android1" /></a> </dt></dl><br style="clear: both" /> </div> <br /><div class="play-store-container"> <div class="play-store-table"> <div id="play-store-app-icon"><a href="https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui" target="_blank" rel="nofollow"><img src="https://lh3.ggpht.com/eeTyBW3zE2RE63KcXwHdaC1eM6oL70vArWu_JAQ-uuDBujPvB3XUocy2nXMj42eXG0nd" alt="logo-app" /></a></div><div id="play-store-text"><a href="https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui" target="_blank" rel="nofollow"><strong><span class="play-store-app-name">Spotify</span></strong></a><a id="play-store-icon" href="https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui"><img src="http://developer.android.com/images/brand/sk_generic_rgb_wo_60.png" alt="play-store-link" width="150px"/></a><br /> <span class="play-store-developer">Spotify Ltd.</span> </span><br /> <span class="play-store-price">0</span>   <div class="stars-container"> <div class="tiny-star"> <div class="current-rating" style="width: 82.84838676452637%;"></div> </div> </div> </div></div></div><br /> "

I have been trying to get only text content and image urls from this using jsoup library, but I cant get #gallery-1 stuff dissapear.

What I would like the output string to look like :

Spotify je známy prehrávač, ktorý prehráva hudbu z internetu – nepotrebujete nič sťahovať. Dnes bola na aplikáciu vydaná nová aktualizácia, ktorá prináša užitočné zmeny.


Užívateľov tejto aplikácie poteší nový tmavý design, ktorý je na oko celkom pekný. Vývojári ním chceli najmä zvýrazniť obsah a použiť moderné prvky. Ja síce túto aplikáciu veľmi nepoužívam, no som veľmi rád, že sa rozhodli pre niečo tmavšie, keďže mi ten biely design v tme ťahal oči.

Ďalšia nová vec je sekcia “Your Music”, ktorá slúži na vytvorenie vlastného playlistu (zoznamu skladieb). Poslednou novinkou v tejto aktualizácií je zlepšenie vyhľadávania podľa lokalizácie a relevancie.

How to make something like this?

EDIT : my code

   public static String html2text(String html) { 
        Document doc = Jsoup.parse(html);       
                Elements els = doc.select("gallery");       
for(Element e: els){e.remove();}
return doc.body().text();}
도움이 되었습니까?

해결책

If you're trying to remove all the CSS styling from the document, including the inside the tags and the style tags themselves, try using:

doc.getElementsByTag("style").remove();
doc.select("[style]").removeAttr("style");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top