我有以下密码:
public class NewClass {
public String noTags(String str){
return Jsoup.parse(str).text();
}
public static void main(String args[]) {
String strings="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN \">" +
"<HTML> <HEAD> <TITLE></TITLE> <style>body{ font-size: 12px;font-family: verdana, arial, helvetica, sans-serif;}</style> </HEAD> <BODY><p><b>hello world</b></p><p><br><b>yo</b> <a href=\"http://google.com\">googlez</a></p></BODY> </HTML> ";
NewClass text = new NewClass();
System.out.println((text.noTags(strings)));
}
结果是:
hello world yo googlez
但是我想打破这个界限:
hello world
yo googlez
我看过 Jsoup 的 TextNode # getWhole Text (),但我不知道如何使用它。
如果我解析的标记中有一个 <br>,那么我如何在结果输出中得到一个换行符呢?