5

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!

aaron
  • 1,951
  • 3
  • 27
  • 41

2 Answers2

16

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

pguardiario
  • 53,827
  • 19
  • 119
  • 159
0

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
nkm
  • 5,844
  • 2
  • 24
  • 38