Jsoup is escaping content of iframe

2019-01-28 08:53发布

问题:

I have this in source html that I want to parse

<div>
<iframe><script>alert('hello')</script></iframe>
</div>

When I parse using Jsoup and print the body html I get this.

<div>
<iframe>&lt;script&gt;alert('hello')&lt;/script&gt;</iframe>
</div>

I don't want Jsoup to convert the content inside iframe. How can I do this?. Sample code

Document doc = Jsoup.parse(html);
System.out.println(doc.body().html());

回答1:

You can use the unescapeEntities(String,boolean) method of jsoup parser :

 Document doc = Jsoup.parse(html);            
 System.out.println(org.jsoup.parser.Parser.unescapeEntities(doc.body().html(), true));