【发布时间】:2020-10-01 14:01:22
【问题描述】:
我想获取一个 HTML 字符串并返回一个保留 HTML 结构但带有混淆文本/内部 HTML 的变异版本。
例如:
string = "<div><p><h1>this is some sensitive text</h1><br></p><p>more text</p></div>"
obfuscate_html_string(string)
=> "<div><p><h1>**** **** **** **** ****</h1><br></p><p>**** ****</p></div>"
我进行了实验,虽然 inner_html= 方法似乎很有用,但它引发了一个参数错误:
Nokogiri::HTML.fragment(value).traverse { |node| node.content = '***' if node.inner_html }.to_s
=> "***"
Nokogiri::HTML.fragment(value).traverse { |node| node.content ? node.content = '***' : node.to_html }.to_s
=> "***"
Nokogiri::HTML.fragment(value).traverse { |node| node.inner_html = '***' if node.inner_html }.to_s
=> ArgumentError: cannot reparent Nokogiri::XML::Text there
【问题讨论】:
-
请参阅“How to Ask”、“Stack Overflow question checklist”和“MCVE”及其所有链接页面。我们无法运行您的代码的最小示例来复制问题。您的问题已包含在 Nokogiri 备忘单和教程中。
标签: html ruby nokogiri obfuscation