新手问题 (Solved) 用 mechanize 出现问题。。似乎是 mechanize 没装对

jt_today · 2012年10月28日 · 最后由 fsword 回复于 2012年10月28日 · 2344 次阅读

版本 Ubuntu 12.04,ruby 1.8.7,gem 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:4: 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

这是什么原因呐

把我的程序重命名一下似乎就好了。

#1 楼 @jt_today 你的程序就叫 mechanize?那在 require 'mechanize'的时候就已经与你想的不同了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号