我有以下内容:
"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 /> "我一直试着只从这里获取文本内容和图像urls,但我不能得到#图片库-1的东西不皂化。
我希望输出字符串看起来像什么:
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.怎么做这样的东西?
编辑:我的代码
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();}发布于 2014-04-30 18:46:51
如果您试图从文档中删除所有CSS样式,包括标记内部和样式标记本身,请尝试使用:
doc.getElementsByTag("style").remove();
doc.select("[style]").removeAttr("style");https://stackoverflow.com/questions/23395383
复制相似问题