我在 ubuntu 12.04 上使用 ruby 1.8.7 和 rubygem 1.8.15
首先,我输入 sudo gem install mechanize --no-ri --no-rdoc
它似乎运作良好。
Building native extensions. This could take a while...
Fetching: ntlm-http-0.1.1.gem (100%)
WARNING: ntlm-http-0.1.1 has an invalid nil value for @cert_chain
Fetching: webrobots-0.0.13.gem (100%)
Fetching: unf_ext-0.0.5.gem (100%)
Building native extensions. This could take a while...
Fetching: unf-0.0.5.gem (100%)
Fetching: domain_name-0.5.4.gem (100%)
Fetching: mechanize-2.5.1.gem (100%)
Successfully installed nokogiri-1.5.5
Successfully installed ntlm-http-0.1.1
Successfully installed webrobots-0.0.13
Successfully installed unf_ext-0.0.5
Successfully installed unf-0.0.5
Successfully installed domain_name-0.5.4
Successfully installed mechanize-2.5.1
7 gems installed
然后我写了我的第一个程序
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
它只是不起作用
./mechanize.rb uninitialized constant Mechanize (NameError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in gem_original_require'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from mechanize.rb:2
有人可以帮我吗?
最佳答案
将您的文件重命名为“mechanize-test.rb”或其他名称以避免与库混淆。它看起来像 1.8 的 require
行为异常。
关于ruby - 我在 ruby 中安装 Mechanize 时的一些问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13105954/