def login(username, password):
br = mechanize.Browser()
login_url = "http://cyclebabac.com/wp-login.php"
# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
# Want debugging messages? Uncomment this
#br.set_debug_http(True)
#br.set_debug_redirects(True)
#br.set_debug_responses(True)
# Perform the actual login
br.open(login_url)
br.select_form(nr=0)
br.form['log'] = str(username)
br.form['pwd'] = str(password)
br.submit()
return br
评论列表
文章目录