问题
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