Jsoup正在逃避iframe的内容 [英] Jsoup is escaping content of iframe

查看:192
本文介绍了Jsoup正在逃避iframe的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

当我使用Jsoup解析并打印body html时,我得到了这个结果。

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

我不想让Jsoup转换iframe中的内容。我怎样才能做到这一点?。示例代码

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


解决方案

您可以使用unescapeEntities(String,boolean)方法jsoup解析器:

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


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

解决方案

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

这篇关于Jsoup正在逃避iframe的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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