作者:手机用户2502927973 | 来源:互联网 | 2023-05-27 13:50
ImhavinganissuegettingNokogiritoworkproperly.Imusingversion1.4.4withRuby1.9.2.我遇到了
I'm having an issue getting Nokogiri to work properly. I'm using version 1.4.4 with Ruby 1.9.2.
我遇到了让Nokogiri正常工作的问题。我正在使用版本1.4.4和Ruby 1.9.2。
I have both libxml2 libxslt installed and up to date. When I run a Ruby script with XML, it works great.
我安装了libxml2 libxslt并且是最新的。当我使用XML运行Ruby脚本时,它运行良好。
require 'nokogiri'
doc = Nokogiri::XML(File.open("test.xml"))
doc = doc.css("name").each do |node|
puts node.text
end
Enter into the CL, run ruby test.rb
, returns
进入CL,运行ruby test.rb,返回
Name 1
Name 2
Name 3
And the crowd goes wild. I tweak a few things, make a few adjustments to the code...
人群疯狂。我调整了一些事情,对代码做了一些调整......
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open("http://domain.tld"))
doc = doc.css("p").each do |node|
puts node.text
end
Back to CL, ruby test.rb
, returns... nothing! Just a new, empty line.
回到CL,ruby test.rb,返回......什么都没有!只是一个新的空行。
Is there any reason that it will work with an XML file, but not HTML?
是否有任何理由可以使用XML文件,而不是HTML?
1 个解决方案