我试图以一种形式注册。但我怎么知道它是否有效,或者表格给出了什么错误(比如密码短)
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()
答案 0 :(得分:1)
req = br.submit()
会将html页面返回req
。使用print req
或print req.read()
查看输出。如果成功登录,则req将包含登录页面