Just trying to run the example ***** require ''rubygems'' require ''mechanize'' a = WWW::Mechanize.new a.get(''http://rubyforge.org/'') do |page| # Click the login link login_page = a.click(page.links.text(/Log In/)) # Submit the login form my_page = login_page.form_with(:action => ''/account/login.php'') do |f| f.form_loginname = ARGV[0] f.form_pw = ARGV[1] end.click_button my_page.links.each do |link| text = link.text.strip next unless text.length > 0 puts text end end ***** with command /opt/local/bin/ruby rubyforge.rb but getting rubyforge.rb:7: undefined method `text'' for #<Array:0x16d2940> (NoMethodError) from /opt/local/lib/ruby/gems/1.8/gems/mechanize-0.9.2/lib/www/mechanize.rb:232:in `get'' from rubyforge.rb:5 Installed mechanize with sudo /opt/local/bin/gem install mechanize which resulted in /opt/local/lib/ruby/gems/1.8/gems/mechanize-0.9.2/ System is Mac OS X 10.4.11 ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin8] -- Andreas R. Formiconi ************************** Blog: http://iamarf.wordpress.com/ Wiki: http://infomedfi.pbwiki.com/ Blog Clown in corsia: http://m-illumino-d-immenso.blogspot.com/ Distribuzione dispense MedWiki: http://www.medwiki.it/ Studente del corso "Connectivism and Connective Knowledge Online Course" http://ltc.umanitoba.ca/wiki/Connectivism ************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20090409/6d1fe794/attachment.html>
On Thu, Apr 9, 2009 at 4:07 AM, Andreas Formiconi < andreas.formiconi at gmail.com> wrote:> Just trying to run the example > > ***** > require ''rubygems'' > require ''mechanize'' > > a = WWW::Mechanize.new > a.get(''http://rubyforge.org/'') do |page| > # Click the login link > login_page = a.click(page.links.text(/Log In/))[snip]> rubyforge.rb:7: undefined method `text'' for #<Array:0x16d2940> > (NoMethodError) > from /opt/local/lib/ruby/gems/1.8/gems/mechanize-0.9.2/lib/www/mechanize.rb:232:in > `get'' > from rubyforge.rb:5 >The error message tells you line 7, which is login_page = ... A page.links returns an Array, which -- like the error messages says-- does not have a #text method. You''re going to have to choose one link from the Array somehow and pass that to a.click(). You probably want something like: login_page = a.click(page.links.select{|x| x.text =~ /Log In/}.first) Personally I would not chain all that stuff together without making sure my #select and #first return a non-empty, non-null value. But to each his own. -Michael -- Michael C. Libby www.mikelibby.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20090409/3aef4dc5/attachment.html>