0

听完 Rails Cast No 190 我坐下来试了一下

所以我安装了 nokogiri

gem install nokogiri

在我的 Windows 7 Ultimate 笔记本电脑上。我使用 Ruby 1.9

这就是我安装 Nokogiri 的方式

C:\Ruby>gem install nokogiri
Successfully installed nokogiri-1.4.2-x86-mingw32
1 gem installed
Installing ri documentation for nokogiri-1.4.2-x86-mingw32...
Updating class cache with 1221 classes...
Installing RDoc documentation for nokogiri-1.4.2-x86-mingw32...

现在为以下代码hello.rb

require 'rubygems'  
require 'nokogiri'  
require 'open-uri'  

url = "http://timesofindia.indiatimes.com/rssfeeds/-2128838597.cms"  
doc = Nokogiri::HTML(open(url))  
puts doc.at_css("title").text 

我试图以标题的形式获得结果,但出现以下错误!

C:\Ruby>ruby hello.rb
C:/Ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.2-x86-mingw32/lib/nokogiri/nokogir
i.rb:1:in `require': 127: The specified procedure could not be found.   - Init_n
okogiri (LoadError)
C:/Ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.2-x86-mingw32/lib/nokogiri/1.9/nok
ogiri.so
        from C:/Ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.2-x86-mingw32/lib/nok
ogiri/nokogiri.rb:1:in `<top (required)>'
        from C:/Ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.2-x86-mingw32/lib/nok
ogiri.rb:13:in `require'
        from C:/Ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.2-x86-mingw32/lib/nok
ogiri.rb:13:in `<top (required)>'
        from hello.rb:2:in `require'
        from hello.rb:2:in `<main>'

我试图卸载并重新安装,gem uninstall nokogiri但我仍然无法摆脱错误。

请帮我解决它!

谢谢

高塔姆

4

2 回答 2

0

当您安装 Nokogiri 时,您是否收到以下问题,您选择了什么选项?

 C:\Documents and Settings\Username>gem install nokogiri
 Bulk updating Gem source index for: http://gems.rubyforge.org
 Select which gem to install for your platform (i386-mswin32)
  1. nokogiri 1.0.6 (ruby)
  2. nokogiri 1.0.6 (x86-mswin32-60)
  3. nokogiri 1.0.5 (x86-mswin32-60)
  4. nokogiri 1.0.5 (ruby)
  5. Skip this gem
  6. Cancel installation
 >

您应该选择 x86-mswin32-60 版本。看起来您安装了非 Windows 版本。

如果您选择了其中一个 ruby​​ 选项,请尝试gem uninstall nokogiri然后再次安装

于 2010-05-26T15:26:48.300 回答
0

这似乎是 Ruby 1.9.1 的一个已知问题。使用 Ruby 1.8.7 再次尝试以缩小您的问题范围。

于 2010-05-26T16:45:25.413 回答