登录后机械化不会重定向到主URL

时间:2014-09-01 14:12:30

标签: python mechanize

我正在尝试使用python mechanize登录我的股票经纪人网站。我已成功登录,但mechanize未重定向到主页面。

我想访问网址:https://secure.icicidirect.com/NewSiteTrading/trading/equity/Trading.aspmechanize停在网址:https://secure.icicidirect.com/NewSiteTrading/customer/validlogon.asp?nFile=tradehome

import mechanize
br = mechanize.Browser()
url = 'https://secure.icicidirect.com/NewSiteTrading/customer/logon.asp'
br.set_handle_redirect(True)
br.set_debug_http(True)
br.set_debug_redirects(True)
br.open(url)
for form in br.forms():
print form
br.select_form(nr=3)
br.form['FML_USR_ID'] = 'username'
br.form['FML_USR_USR_PSSWRD'] = 'password'
br.form['FML_USR_DT_BRTH'] = 'dateofbirth'
br.submit()
br.geturl()

1 个答案:

答案 0 :(得分:0)

登录后,只需在同一个机械化会话中打开主页:

br.open('https://secure.icicidirect.com/NewSiteTrading/trading/equity/Trading.a‌​sp')