【问题标题】:jsoup: removing iframe tagsjsoup:删除 iframe 标签
【发布时间】:2011-11-09 02:08:56
【问题描述】:

我正在使用 jsoup 1.6.1 并在尝试从 html 中删除 iframe 标记时遇到问题。当 iframe 没有任何正文时(即 ),remove() 方法会删除 t 标记后的所有内容。这是我的示例代码。

String html ="<p> This is start.</p><iframe frameborder="0" marginheight="0" /><p> This is end</p>";
Document doc = Jsoup.parse(html,"UTF-8");<br>
doc.select("iframe").remove();<br>
System.out.println(doc.text());

它回到我身边 -

This is start.

但我期待结果 -

This is start. This is end

提前致谢

【问题讨论】:

    标签: java jsoup


    【解决方案1】:

    看来 iframe 的结束标记是必需的。你不能使用自闭标签:

    http://msdn.microsoft.com/en-us/library/ie/ms535258(v=vs.85).aspx http://stackoverflow.com/questions/923328/line-after-iframe-is-not-visible http://www.w3resource.com/html/iframe/HTML-iframe-tag-and-element.php

    所以,Jsoup 遵循规范并采用 iframe 标记之后的任何内容并将其用作其主体。当您移除 iframe 时,“This is the end”会随之移除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 2012-01-20
      • 1970-01-01
      • 2023-01-04
      相关资源
      最近更新 更多