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>标签等。清洁器不起作用。我究竟做错了什么?

4

1 回答 1

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");
于 2012-06-12T14:39:04.550 回答