如何使Nokogiri不转换太空 [英] how to make Nokogiri not to convert   to space
问题描述
我获取了一个类似html的片段
i fetch one html fragment like
"<li>市 场 价"
包含"
",但是在调用Nokogiri NodeSet的to_s
之后,它将变为
which contains "
", but after calling to_s
of Nokogiri NodeSet, it becomes
"<li>市 场 价"
,我想保留原始的html片段,并尝试为to_s
方法设置:save_with option
,但是失败了.
, i want to keep the original html fragment, and tried to set :save_with option
for to_s
method, but failed.
有人可以遇到相同的问题并给我帮助吗?预先谢谢你.
can someone encounter the same problem and give me help? thank you in advance.
推荐答案
我遇到了类似的情况,但我提出的建议有点破解,但似乎效果很好.
I encountered a similar situation, and what I came up was a bit of a hack, but it seems to work well.
nbsp = Nokogiri::HTML(" ").text
text.gsub(nbsp, " ")
就我而言,我希望nbsp成为常规空间.我认为在您的情况下,您希望将它们返回到& nbsp;",因此您可以执行以下操作:
In my case, I wanted the nbsp to be a regular space. I think in your case, you want them to be returned to a " ", so you could do something like:
nbsp = Nokogiri::HTML(" ").text
html.gsub(nbsp, " ")
这篇关于如何使Nokogiri不转换太空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!