mechanize login problem

P

Pen Ttt

require 'rubygems'
require 'mechanize'
agent = WWW::Mechanize.new
agent.user_agent_alias = 'Windows IE 7'
page = agent.post("http://sso.chinaunix.net/Login?")
form = page.forms[0]
form['login_name'] = 'luofeiyu'
form['password'] = 'qwerty'
page = agent.submit(form)
page.save("/home/pt/web")

irb(main):166:0> form = page.forms[0]
=> nil
irb(main):167:0> form['login_name'] = 'luofeiyu'
NoMethodError: undefined method `[]=' for nil:NilClass
from (irb):167
from :0
irb(main):168:0> form['password'] = 'qwerty'
NoMethodError: undefined method `[]=' for nil:NilClass
from (irb):168
from :0
irb(main):169:0> page = agent.submit(form)
ArgumentError: wrong number of arguments (0 for 1)
from /var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:368:in
`method'
from /var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:368:in
`submit'
from (irb):169
from :0
would you mind to tell me what wrong is?
 
P

Pen Ttt

view-page source ,you can see :
<form id="frmLogin" name="frmLogin" method="post" action=""
class="sso_checked">
<input type="hidden" name="cookie_flag">
<div class="login">

<p class="title">欢迎您<br />å·²ç»æ‹¥æœ‰ChinaUnixå¸æˆ·</p>
<p class="mt8">
用户å:<input type="text" id="login_name" name="login_name"
size="20" maxlength="30" class="inputText1 {required:true,minLength:2}"
value="" />
</p>
<p class="mt8">
密&nbsp;&nbsp;ç ï¼š<input type="password" id="password"
name="password" size="20" maxlength="30" class="inputText1
{required:true,minLength:4}">

</p>
<p class="mt8">
<input type="checkbox" value="30" id="furmcookie"
name="furmcookie">è®°ä½æˆ‘的密ç 
<input type="submit" name="btn_login" value="登录" class="button1"
style=" float:right; margin-top:-20px; ">
</p>
<div class="clear"></div>
</div>
<div class="w285">
<p class="title">还ä¸æ˜¯ChinaUnix会员?立å³å…费注册ï¼</p>

<p class="mt12 tr"><input type="button" value="注 册"
class="button1"
onclick="javascript:window.location.href='/Register'"/></p>

<dl class="lh18 mt10">
<dt class="bold">为什么è¦æ³¨å†Œï¼Ÿ</dt>
<dd>
您åªæœ‰æ³¨å†Œæˆä¸ºChinaUnix会员,æ‰å¯ä»¥ç™»å½•è®ºå›ã€åšå®¢å‘言交æµï¼Œå¹¶å¯ä»¥äº«ç”¨ChinaUnixçš„å„项æœåŠ¡ã€‚
</dd>
</dl>
</div>



<div class="forget">

<p class="title">忘记密ç æˆ–ID</p>
<p class="con">如果你忘记了你的密ç ï¼Œè¯·åœ¨è¿™é‡Œæ‰¾å›žå¯†ç ã€‚</p>

<p class="tr mt8"><input type="button" value="找回密ç "
class="button1"
onclick="javascript:window.location.href='/ForgotPassword'"/></p>

</div>

</form>

there is form in it.
 

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

Top