2
試圖使用機械化登錄到網站。當我打印「br.form」時,我可以看到我的憑證輸入到我的表單中。但我不知道如何正確提交表單。使用Python的機械化模塊驗證br.submit()
我使用「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()