Problem with Mechanize

Z

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' => '(e-mail address removed)',
'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!
 
Æ

æŽå…‰

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' => '(e-mail address removed)',
'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!
晕,你也é‡åˆ°è¿™ä¸ªé—®é¢˜äº†ã€‚我的问题和你一样。呵呵。准备对开心网下手~?
 
Z

Zhang Zhai

你好,呵呵,想练练手咯。其他站点都å¯ä»¥ï¼Œå°±è¿™ä¸ªä¸è¡Œï¼Œéƒé—·ã€‚


æŽå…‰ said:
Zhang Zhai 写é“:
@verbose = verbose
login_form.password = @auth['password']
kx.login
`bases': undefined method `search' for nil:NilClass (NoMethodError)
c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize.rb:433:in
from
Can anyone help?thanks!
晕,你也é‡åˆ°è¿™ä¸ªé—®é¢˜äº†ã€‚我的问题和你一样。呵呵。准备对开心网下手~?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top