新手问题 用 mechanize 登录怎么处理跳转

jt_today · 2012年10月29日 · 最后由 jt_today 回复于 2012年10月29日 · 3086 次阅读
require 'rubygems'
require 'mechanize'

agent = Mechanize.new
page = agent.get("https://example.com/login")
login_form = page.forms.first
login_form.username = 'username'
login_form.password = 'password'
page = agent.submit(login_form)
pp page

代码如上。可是登录后有个跳转页,显示的是

#<Mechanize::Page
 {url #<URI::HTTPS:0xb6c5e764 URL:https://example.com/takelogin.php>}
 {meta_refresh #<Mechanize::Page::MetaRefresh "" "index.php">}
 {title nil}
 {iframes}
 {frames}
 {links}
 {forms}>

新手请教怎么处理这个跳转页

用笨办法解决了……

agent = Mechanize.new
page = agent.get("https://example.com/login")
login_form = page.forms.first
login_form.username = 'username'
login_form.password = 'password'
agent.submit(login_form)
page = agent.get("https://example.com/index.php")
pp page

但是还是不知道如何处理跳转

需要 登录 后方可回复, 如果你还没有账号请 注册新账号