jsoup解析页面保留换行符
前言
jsoup解析页面默认是不包含换行符的,如果需要保留换行符,需要单独设置。
实现过程
String html = "</html>....</html>"
Document document = Jsoup.parse(html);
document.outputSettings(new Document.OutputSettings().prettyPrint(false));
document.select("br").append("\\n");
document.select("p").prepend("\\n");
String html1 = document.toString()
总结
上面只是简单的示例,大家可以自行尝试。