Zhang Zhai 继苹: > Hi, > > I want to use Mechanize to login a sns site.Here is my test code. > > require 'rubygems' > require 'mechanize' > > class Kaixin > def initialize(auth, verbose = false) > @auth = auth > @verbose = verbose > @agent = WWW::Mechanize.new > @agent.redirect_ok = true > end > > def login > > page = @agent.get('http://www.kaixin001.com/') > > login_form = page.forms.first > login_form.email = @auth['email'] > login_form.password = @auth['password'] > page1 = @agent.submit(login_form) > > pp page1 if @verbose > end > > end > > auth = {'email' => 'xxx / gmail.com', > 'password' => 'xxx'} > kx = Kaixin.new(auth, true) > kx.login > > > I use most of the demo code.So i cant see whats the problem.If i type > the error password,its no page error.if i type the correct pwd,then it > goes wrong,I find the page use the redirect from "/login" to "/home" > ,does this matter? > > Here is the output of netbeans: > > c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize/page.rb:118:in > `bases': undefined method `search' for nil:NilClass (NoMethodError) > > from > c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize/chain/uri_resolver.rb:37:in > `handle' > > from > c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize/chain.rb:25:in > `handle' > > from > c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize.rb:433:in > `fetch_page' > > from > c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize.rb:509:in > `fetch_page' > > from > c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize.rb:392:in > `post_form' > > from > c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize.rb:324:in > `submit' > > from J:\ROR\RubyProjects\test1\lib/kaixin.rb:20:in `login' > > from J:/ROR/RubyProjects/test1/lib/main.rb:8 > > > > > Can anyone help?thanks! > ·涕而毗肖位。叉弄下办。谊谊。节看姒布缄~々