未初始化的常量在ruby中使用mechanize gem时的机械化

时间:2017-10-05 05:02:34

标签: ruby mechanize

我正在尝试使用机械化进行网页抓取,但它在开始时已经给我一个错误。

require 'rubygems'
require "mechanize"

agent = Mechanize.new { |agent|
  agent.user_agent_alias = 'Mac Safari'
}

page = agent.get('https://www.wikipedia.org/')

searchForm = page.form(:action => '//www.wikipedia.org/search-redirect.php')

错误看起来像

C:/Users/user/eclipse-workspace/proj/mechanize.rb:4:in `<top (required)>': uninitialized constant Mechanize (NameError)
    from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from C:/Users/user/eclipse-workspace/proj/mechanize.rb:2:in `<main>'

0 个答案:

没有答案