[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Problem with Mechanize

Zhang Zhai

10/1/2008 4:23:00 PM

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...)

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!
--
Posted via http://www.ruby-....

2 Answers

??

10/23/2008 4:03:00 PM

0

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...)
>
> 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!
>
æ??ï¼?ä½ ä¹?é?å?°è¿?个é?®é¢?äº?ã??æ??ç??é?®é¢?å??ä½ ä¸?æ ·ã??å?µå?µã??å??å¤?对å¼?å¿?ç½?ä¸?æ??~ï¼?


Zhang Zhai

11/1/2008 1:54:00 AM

0

你好ï¼?å?µå?µï¼?æ?³ç»?ç»?æ??å?¯ã??å?¶ä»?ç«?ç?¹é?½å¯ä»¥ï¼?å°±è¿?个不è¡?ï¼?é?é?·ã??


æ?å?? wrote:
> 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!
>>
> æ??ï¼?ä½ ä¹?é?å?°è¿?个é?®é¢?äº?ã??æ??ç??é?®é¢?å??ä½ ä¸?æ ·ã??å?µå?µã??å??å¤?对å¼?å¿?ç½?ä¸?æ??~ï¼?

--
Posted via http://www.ruby-....