Problem with Mechanize

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’ => ‘[email protected]’,
‘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 methodsearch’ 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 写道:

@verbose = verbose
login_form.password = @auth['password']

kx.login
bases': undefined methodsearch’ 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!

æ™•ï¼Œä½ ä¹Ÿé‡åˆ°è¿™ä¸ªé—®é¢˜äº†ã€‚æˆ‘çš„é—®é¢˜å’Œä½ ä¸€æ ·ã€‚å‘µå‘µã€‚å‡†å¤‡å¯¹å¼€å¿ƒç½‘ä¸‹æ‰‹~?

ä½ å¥½ï¼Œå‘µå‘µï¼Œæƒ³ç»ƒç»ƒæ‰‹å’¯ã€‚å…¶ä»–ç«™ç‚¹éƒ½å¯ä»¥ï¼Œå°±è¿™ä¸ªä¸è¡Œï¼Œéƒé—·ã€‚

李光 wrote:

Zhang Zhai 写道:

@verbose = verbose
login_form.password = @auth['password']

kx.login
bases': undefined methodsearch’ 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!

æ™•ï¼Œä½ ä¹Ÿé‡åˆ°è¿™ä¸ªé—®é¢˜äº†ã€‚æˆ‘çš„é—®é¢˜å’Œä½ ä¸€æ ·ã€‚å‘µå‘µã€‚å‡†å¤‡å¯¹å¼€å¿ƒç½‘ä¸‹æ‰‹~?