Python - 机械化 - 如何知道它是否有效?

时间:2014-09-25 02:28:10

标签: python mechanize

我试图以一种形式注册。但我怎么知道它是否有效,或者表格给出了什么错误(比如密码短)

import mechanize

br = mechanize.Browser()
br.open("http://www.gutefrage.net/nutzer_hinzufuegen")
br.select_form(name = "regForm")

br.form['fRegister[nickname]'] = 'Username'
br.form['fRegister[email]'] = 'email@email.com'
br.form['fRegister[password]'] = 'password'
for i in range(0, len(br.find_control(name="fRegister[accept]").items)):
br.find_control(name="fRegister[accept]").items[i].selected =True

req = br.submit()

1 个答案:

答案 0 :(得分:1)

提交后,

req = br.submit()会将html页面返回req。使用print reqprint req.read()查看输出。如果成功登录,则req将包含登录页面