只是想登录到使用机械化网站。 当我打印“br.form”,我可以看到进入我的形式我的凭据。 但我不知道如何实际正确提交表单。
我用“br.submit()”,并试图通过打印br.title()来验证它已经前进到下一个页面,但出现的标题是登录屏幕,而不是登录后屏幕。
import mechanize
from time import sleep
def reportDownload():
# Prompt for login credentials
print("We require your credentials.")
Username = raw_input("Please enter your username. ")
Password = raw_input("Please input your password. ").encode('base64')
URL = "https://login.xxxxxxxxx.com/"
br = mechanize.Browser()
br.open(URL)
br.select_form(nr=0)
br['username'] = Username
br['pw'] = Password.decode('base64')
print br.form
# Login
br.submit()
# print page title to confirm proper login
print br.title()
reportDownload()