using mechanize and got the uninitialized constant Object::WWW (NameError)

你说的曾经没有我的故事 提交于 2019-12-23 10:58:56

问题


I'm using mechanize in windows 7 x64 OS, but got the the uninitialized constant Object::WWW (NameError),

the code is very simple:

require 'rubygems'
require 'mechanize'
agent = WWW::Mechanize.new

error occurs at the line agent = WWW::Mechanize.new

any help is appreciated!


回答1:


remove the WWW:: - that got removed a long time ago.




回答2:


While googling found the following code, may be useful to you.

@a = Mechanize.new { |agent|
      agent.user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; es-ES; rv:1.9
.2.3) Gecko/20100401 Firefox/6.0.2'
    }
@a.get("http://www.somesite.com"]) do |page|
      page.search("//a[id='id-name']"]).each do |a|
      puts a
end


来源:https://stackoverflow.com/questions/8860486/using-mechanize-and-got-the-uninitialized-constant-objectwww-nameerror

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!