我正在尝试登录http://chess.com/login以便我可以访问一些下载链接,但我似乎无法通过机械化来提交我的登录凭据。我的代码如下所示:
import mechanize
def login(username, password):
br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
login = br.open('http://chess.com/login')
br.select_form(nr = 0)
br.form['c1'] = username
br.form['loginpassword'] = password
br.method = 'POST'
resp = br.submit()
login_check = resp.read()
testfile = open('test.html','w+')
testfile.write(login_check)
然而,当我检查testfile html时,它返回登录页面,只返回表单数据输入。我做错了什么?