Avoid removing spaces and newlines when parsing html with jsoup
I have a sample code as below.
String sample = "<html>
<head>
</head>
<body>
This is a sample on parsing html body using jsoup
This is a sample on parsing html body using jsoup
</body>
</html>";
Document doc = Jsoup.parse(sample);
String output = doc.body().text();
I get output as
This is a sample on parsing html body using jsoup This is a sample on `parsing html body using jsoup`
But I want the result to be
This is a sample on parsing html body using jsoup
This is a sample on parsing html body using jsoup
How to do parsing to get this result? Or is there any other way to do this in Java?