Note that there are some explanatory texts on larger screens.

plurals
  1. POPreserving lines with Jsoup
    primarykey
    data
    text
    <p>I am using Jsoup to get some data from html, I have this code:</p> <pre><code>System.out.println("nie jest"); StringBuffer url=new StringBuffer("http://www.darklyrics.com/lyrics/"); url.append(args[0]); url.append("/"); url.append(args[1]); url.append(".html"); //wyciaganie odpowiednich klas z naszego htmla Document doc=Jsoup.connect(url.toString()).get(); Element lyrics=doc.getElementsByClass("lyrics").first(); Element tracks=doc.getElementsByClass("albumlyrics").first(); //Jso //lista sciezek int numberOfTracks=tracks.getElementsByTag("a").size(); </code></pre> <p>Everything would be fine, I extracthe data I want, but when I do:</p> <pre><code>lyrics.text() </code></pre> <p>I get the text with no line breaks, so I am wondering how to leave line breaks in displayed text, I read other threads on stackoverflow on this matter but they weren't helpful, I tried to do something like this:</p> <pre><code>TextNode tex=TextNode.createFromEncoded(lyrics.text(), lyrics.baseUri()); </code></pre> <p>but I can't get the text I want with line breaks. I looked at previous threads about this like, <a href="https://stackoverflow.com/questions/5348455/removing-html-entities-while-preserving-line-breaks-with-jsoup">Removing HTML entities while preserving line breaks with JSoup</a> but I can't get the effect I want. What should I do?</p> <p>Edit: I got the effect I wanted but I don't think it is very good solution:</p> <pre><code>for (Node nn:listOfNodes) { String s=Jsoup.parse(nn.toString()).text(); if ((nn.nodeName()=="#text" || nn.nodeName()=="h3")) { buf.append(s+"\n"); } } </code></pre> <p>Anyone got better idea?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload