2011-06-27 5 views
3

私はMechanize経由でログインフォームを送信しようとしていますが、送信時に何も起こりません。もう一度空のログインフォームが表示されます。フォームにはIDのみがあり、名前はないので、インデックスにアクセスしています。私は100%自信を持っているわけではありません。適切なフォームに記入することさえできますので、id = "user-login"のフォームに直接アクセスすると助かります。ありがとうございました!ここでMechanize form.submitは空のフォームを返します

は私のコードです:

require 'rubygems' 
require 'mechanize' 
require 'logger' 

login_url = "http://www.peersnet.org/user/login" 
agent = Mechanize.new{|a| a.log = Logger.new(STDERR) } 
agent.user_agent_alias = 'Mac Safari' 
page = agent.get(login_url) 
form = page.forms[1] 
form.name = username 
form.pass = password 
page = form.submit 
puts page.body 

と出力:私はそれをしようとしなかった

require 'rubygems' 
require 'mechanize' 

login_url = "http://www.peersnet.org/user/login" 
agent = Mechanize.new 
agent.user_agent_alias = 'Mac Safari' 
page = agent.get(login_url) 
form = page.form_with(:id => 'user-login') 
form.name = username 
form.pass = password 
page = form.submit 
puts page.body 

I, [2011-06-27T14:08:18.161313 #34326] INFO -- : Net::HTTP::Get: /user/login 
D, [2011-06-27T14:08:18.161442 #34326] DEBUG -- : request-header: accept-language => en-us,en;q=0.5 
D, [2011-06-27T14:08:18.161487 #34326] DEBUG -- : request-header: accept => */* 
D, [2011-06-27T14:08:18.161540 #34326] DEBUG -- : request-header: user-agent => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-at) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10 
D, [2011-06-27T14:08:18.161574 #34326] DEBUG -- : request-header: connection => keep-alive 
D, [2011-06-27T14:08:18.161606 #34326] DEBUG -- : request-header: accept-encoding => gzip,identity 
D, [2011-06-27T14:08:18.161637 #34326] DEBUG -- : request-header: host => www.peersnet.org 
D, [2011-06-27T14:08:18.161669 #34326] DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7 
D, [2011-06-27T14:08:18.161707 #34326] DEBUG -- : request-header: keep-alive => 300 
D, [2011-06-27T14:08:18.214246 #34326] DEBUG -- : Read 2280 bytes 
D, [2011-06-27T14:08:18.214495 #34326] DEBUG -- : Read 3728 bytes 
D, [2011-06-27T14:08:18.228916 #34326] DEBUG -- : Read 3946 bytes 
D, [2011-06-27T14:08:18.229057 #34326] DEBUG -- : response-header: etag => "3eff27922ab4d458eadc2460edefc455" 
D, [2011-06-27T14:08:18.229095 #34326] DEBUG -- : response-header: x-powered-by => PHP/5.2.6-1+lenny10 
D, [2011-06-27T14:08:18.229130 #34326] DEBUG -- : response-header: expires => Sun, 19 Nov 1978 05:00:00 GMT 
D, [2011-06-27T14:08:18.229178 #34326] DEBUG -- : response-header: last-modified => Mon, 27 Jun 2011 19:00:56 GMT 
D, [2011-06-27T14:08:18.229213 #34326] DEBUG -- : response-header: content-type => text/html; charset=utf-8 
D, [2011-06-27T14:08:18.229251 #34326] DEBUG -- : response-header: connection => Keep-Alive 
D, [2011-06-27T14:08:18.229291 #34326] DEBUG -- : response-header: server => Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny10 with Suhosin-Patch 
D, [2011-06-27T14:08:18.229325 #34326] DEBUG -- : response-header: date => Mon, 27 Jun 2011 19:09:50 GMT 
D, [2011-06-27T14:08:18.229365 #34326] DEBUG -- : response-header: content-length => 3946 
D, [2011-06-27T14:08:18.229399 #34326] DEBUG -- : response-header: content-encoding => gzip 
D, [2011-06-27T14:08:18.229433 #34326] DEBUG -- : response-header: set-cookie => SESS823dcdeff457c20dcc3729915d224656=6b452cc3217225dd1143317293459b49; expires=Wed, 20 Jul 2011 22:43:10 GMT; path=/; domain=.peersnet.org 
D, [2011-06-27T14:08:18.229467 #34326] DEBUG -- : response-header: keep-alive => timeout=15, max=100 
D, [2011-06-27T14:08:18.229501 #34326] DEBUG -- : response-header: cache-control => must-revalidate 
D, [2011-06-27T14:08:18.229547 #34326] DEBUG -- : gunzip body 
D, [2011-06-27T14:08:18.230961 #34326] DEBUG -- : saved cookie: SESS823dcdeff457c20dcc3729915d224656=6b452cc3217225dd1143317293459b49 
I, [2011-06-27T14:08:18.231392 #34326] INFO -- : status: 200 
D, [2011-06-27T14:08:18.234560 #34326] DEBUG -- : query: ANONYMIZEDINFOform_id=user_login" 
I, [2011-06-27T14:08:18.236906 #34326] INFO -- : Net::HTTP::Post: /user/login 
D, [2011-06-27T14:08:18.236960 #34326] DEBUG -- : request-header: accept-language => en-us,en;q=0.5 
D, [2011-06-27T14:08:18.237012 #34326] DEBUG -- : request-header: accept => */* 
D, [2011-06-27T14:08:18.237123 #34326] DEBUG -- : request-header: content-type => application/x-www-form-urlencoded 
D, [2011-06-27T14:08:18.237170 #34326] DEBUG -- : request-header: user-agent => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-at) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10 
D, [2011-06-27T14:08:18.237209 #34326] DEBUG -- : request-header: connection => keep-alive 
D, [2011-06-27T14:08:18.237252 #34326] DEBUG -- : request-header: accept-encoding => gzip,identity 
D, [2011-06-27T14:08:18.237286 #34326] DEBUG -- : request-header: content-length => 98 
D, [2011-06-27T14:08:18.237320 #34326] DEBUG -- : request-header: referer => http://www.peersnet.org/user/login 
D, [2011-06-27T14:08:18.237353 #34326] DEBUG -- : request-header: cookie => SESS823dcdeff457c20dcc3729915d224656=6b452cc3217225dd1143317293459b49 
D, [2011-06-27T14:08:18.237386 #34326] DEBUG -- : request-header: if-modified-since => Mon, 27 Jun 2011 19:00:56 GMT 
D, [2011-06-27T14:08:18.237425 #34326] DEBUG -- : request-header: host => www.peersnet.org 
D, [2011-06-27T14:08:18.237459 #34326] DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7 
D, [2011-06-27T14:08:18.237493 #34326] DEBUG -- : request-header: keep-alive => 300 
D, [2011-06-27T14:08:18.560518 #34326] DEBUG -- : Read 945 bytes 
D, [2011-06-27T14:08:18.561055 #34326] DEBUG -- : Read 3969 bytes 
D, [2011-06-27T14:08:18.561177 #34326] DEBUG -- : response-header: x-powered-by => PHP/5.2.6-1+lenny10 
D, [2011-06-27T14:08:18.561234 #34326] DEBUG -- : response-header: last-modified => Mon, 27 Jun 2011 19:09:50 GMT 
D, [2011-06-27T14:08:18.561288 #34326] DEBUG -- : response-header: expires => Sun, 19 Nov 1978 05:00:00 GMT 
D, [2011-06-27T14:08:18.561341 #34326] DEBUG -- : response-header: content-type => text/html; charset=utf-8 
D, [2011-06-27T14:08:18.561401 #34326] DEBUG -- : response-header: connection => Keep-Alive 
D, [2011-06-27T14:08:18.561457 #34326] DEBUG -- : response-header: server => Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny10 with Suhosin-Patch 
D, [2011-06-27T14:08:18.561503 #34326] DEBUG -- : response-header: date => Mon, 27 Jun 2011 19:09:50 GMT 
D, [2011-06-27T14:08:18.561557 #34326] DEBUG -- : response-header: content-length => 3969 
D, [2011-06-27T14:08:18.561603 #34326] DEBUG -- : response-header: content-encoding => gzip 
D, [2011-06-27T14:08:18.561648 #34326] DEBUG -- : response-header: keep-alive => timeout=15, max=99 
D, [2011-06-27T14:08:18.561693 #34326] DEBUG -- : response-header: vary => Accept-Encoding 
D, [2011-06-27T14:08:18.561738 #34326] DEBUG -- : response-header: cache-control => store, no-cache, must-revalidate, post-check=0, pre-check=0 
D, [2011-06-27T14:08:18.561800 #34326] DEBUG -- : gunzip body 
I, [2011-06-27T14:08:18.562356 #34326] INFO -- : status: 200 

答えて

関連する問題