【发布时间】:2011-05-31 02:20:19
【问题描述】:
我正在尝试运行以下代码,其中我使用 nokogiri 解析 xml 文件。我想从文本中消除换行符 包含在标签之间。我在这里的代码曾经可以工作,但由于某种原因,现在不行了。可能是因为我 升级到 ruby-1.9.1。
titles = node.search('b')
titles.each do |e|
unless e.parent.name == "h4"
if e.children.children.first.nil? == false
puts e.children.children.first.text.gsub("\n","")
end
end
end
当我运行代码时出现此错误:
HI. You're using libxml2 version 2.6.16 which is over 4 years old and has
plenty of bugs. We suggest that for maximum HTML/XML parsing pleasure, you
upgrade your version of libxml2 and re-install nokogiri. If you like using
libxml2 version 2.6.16, but don't like this warning, please define the constant
I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 before requring nokogiri.
test.rb:35:in `gsub': invalid byte sequence in UTF-8 (ArgumentError)
【问题讨论】:
-
你愿意不听从建议升级吗?
-
您真的应该遵循建议(升级,而不是隐藏警告!)然后再次测试您的代码。如果错误仍然存在,请发表评论。顺便说一句,您还应该使用 Ruby 1.9.2 而不是 1.9.1!
-
在哪里可以找到在 Mac OSX 中升级 ruby 的说明?据我所知,我只能通过 RVM 来做到这一点
-
混用 Mac OSX 的 Ruby 可能不是一个好主意。我会选择 MacPorts/Fink 或者 Homebrew。