2012-06-12 90 views
1
doc = Jsoup.parse(html2); 
Whitelist whitelist = new Whitelist(); 
Whitelist.simpleText().addTags("table","td", "tr","tbody"); 
Cleaner cleaner = new Cleaner(whitelist); 
cleaner.clean(doc); 

Elements gradesTableBody = doc.select(".user-grade").select("tbody").select("tr"); 
Log.d("output", gradesTableBody.html()); 

輸出html仍包含<img>標籤等清潔工不起作用。我究竟做錯了什麼?Jsoup清潔劑不去除元素

回答

3

Cleaner.clean返回一個新的文件(您目前只是扔掉了)。

你需要做的

doc = cleaner.clean(doc); 
^^^^^ 

而且,這些線是沒有意義的:

Whitelist whitelist = new Whitelist(); 
Whitelist.simpleText().addTags("table","td", "tr","tbody"); 

我想你可能會想要做

Whitelist whitelist = Whitelist.simpleText().addTags("table","td", "tr","tbody");