1
import twill
twill.commands.agent("Mozilla/5.0 (Windows NT 6.2; WOW64; rv:15.0) Gecko/20120910144328 Firefox/15.0.2")
twill.commands.go('loginpage...')
twill.commands.fv("1", "txtUserName", "username")
twill.commands.fv("1", "txtPassword", "password")
# Login Page
twill.commands.submit()
# Pre Registration Report Selection
twill.commands.submit()
# Generate and download the report.
twill.commands.go("ReportGenerator.ashx")
print "Done!"
twill.commands.redirect_output('PreRegistration.xls')
#twill.commands.save_html('PreRegistration.xls')
這就是我正在嘗試使用目前。Python 2.7使用斜紋,正確保存下載的文件
網站可以作爲這樣的:
- 登錄頁面重定向到另一個表單,讓我選擇要生成的報告。
- 我想要所有的默認選項,所以我只需再次提交頁面。
- 然後,我訪問另一個頁面,生成報告,然後強制下載文件。
redirect_output不保存xls文件。
save_html確實保存了信息,但它破壞了某些東西,Excel根本無法讀取它。我使用kdiff來檢查任何差異,它聲稱有很多,但左/右的數據是相同的,想知道這是否與線結束的問題..等等。不是100%確定的。
我檢查了斜紋網站上的命令頁面,但我不確定如何去做這件事。
使用'twill' Cookie jar獲取二進制內容的替代方法'請求':http://stackoverflow.com/questions/37910736/python-twill-download-file-accessible-through-php-script/37911758#37911758 –