【发布时间】:2015-12-13 00:53:28
【问题描述】:
在某些 HTML 中,我想删除一些特定的标签,但保留标签的内容/HTML。例如,在下面的行中,我
想要删除列入黑名单的<strong> 和<div> 标签,但保留标签的内容,并仅从我的白名单标签中保留<p>、<img> 和其他标签:
原文:
<div>
some text
<strong>text</strong>
<p>other text</p>
<img src="http://example.com" />
</div>
结果:
some text
text
<p>other text</p>
<img src="http://example.com" />
我想去除特定标签,某些标签不能去除。它必须像 PHP 中的 strip_tags 一样工作。所以inner_html 帮不了我。
【问题讨论】:
-
@lcguida - 不,因为我想删除指定的标签,你建议获取 inner_html。这是不同的事情。请仔细阅读说明
-
@hakcho 请阅读答案 Alexey Shein,它不是重复的。请仔细阅读说明
标签: html ruby parsing nokogiri