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>标记等。清理程序不起作用。我究竟做错了什么?

最佳答案

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");

关于java - Jsoup清洁器未删除元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10998900/

10-08 22:29