如何使用jsoup整理html [英] how to use jsoup to tidy up the html

查看:76
本文介绍了如何使用jsoup整理html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jsoup,整理一些html真的很好,但是我有一段无效的html,如下所示:

I am using jsoup and it is really nice to tidy up some html, but I have a piece of invalid html as following:

<p>The recurrence, in close succession <ul><li>list item 1</li><li>list item 2</li></ul> second part of thisssss

我想要得到的是:

<p>The recurrence, in close succession </p><ul><li>list item 1</li><li>list item 2</li></ul> <p>second part of thisssss</p>

那么jsoup是否能够整理html并返回此输出?

So is the jsoup capable of tidying up the html and return this output ?

谢谢

推荐答案

是的,请尝试以下操作:

Yes, try this:

String html = "<p>The recurrence, in close succession <ul><li>list item 1</li><li>list item 2</li></ul> second part of thisssss";
String clean = Jsoup.clean(html, Whitelist.relaxed());

您也可以使用另一个白名单.

这篇关于如何使用jsoup整理html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆