-2
我已經反彈到一個小問題。 我得到一個網站的HTML,我得到它格式正確,但這裏的一個問題是,它的圖像有whitespaces加載和文本開始真的很遙遠。獲取HTML確切與Jsoup fromated
有沒有解決這個問題的好方法。下面是我做它:
public class getDetails extends AsyncTask<Void,Void,Void> {
@Override
protected Void doInBackground(Void... voids) {
Document doc,doc_;
String test;
try{
doc = Jsoup.connect(Global_URL).get();
Elements elements = doc.getElementsByClass("entry-content");
doc_ = Jsoup.parse(elements.toString());
doc_.outputSettings(new Document.OutputSettings().prettyPrint(false));
doc_.select("br").append("\\n");
doc_.select("p").prepend("\\n\\n");
test = doc_.html().replaceAll("\\\\n","\n");
test = Jsoup.clean(test,"",Whitelist.none(),new Document.OutputSettings().prettyPrint(false));
dialog_desc = test;
//dialog_desc = elements.text().toString();
}
catch (Exception e){
e.printStackTrace();
}
return null;
}
請提供您正在抓取的HTML的例子,並澄清您想要添加換行符的操作。 –