我正在使用 jsoup 1.6.1,当我尝试从 html 中删除 iframe 标记时遇到问题。当 iframe 没有任何正文(即 <iframe pro=value/>)时,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
提前致谢
最佳答案
看来 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”也会随之删除。
关于java - jsoup:删除 iframe 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7282378/