使用jsoup和字符串构建器解析HTML在最终结果中添加空格。 首先,它显示标题,然后在字符串标题和标记p之间显示标记
的字符串,这里有空格。三江源
MainActivity
TextView tvidescription;
@Override
protected void onCreate ( Bundle savedInstanceState ) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
new Thread(new Runnable() {
@Override
public void run () {
final StringBuilder builder = new StringBuilder();
try {
Document doc = Jsoup.connect("https://jang.com.pk/news/497717").get();
Elements links = doc.select("p");
String title = doc.title();
builder.append(title);
for (Element link : links) {
builder.append("\n").append("\n").append(link.text());
}
} catch (IOException e) {
builder.append("Error : ").append(e.getMessage()).append("\n");
}
runOnUiThread(new Runnable() {
@Override
public void run () {
tvidescription.setText(builder);
}
});
}
}).start();
return null;
}
}
答案 0 :(得分:0)
尝试
doc.outputSettings().prettyPrint(false);
这将删除空格。