2012-10-07 35 views
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使用斜纹,正确保存下载的文件

网站可以作为这样的:

  1. 登录页面重定向到另一个表单,让我选择要生成的报告。
  2. 我想要所有的默认选项,所以我只需再次提交页面。
  3. 然后,我访问另一个页面,生成报告,然后强制下载文件。

redirect_output不保存xls文件。

save_html确实保存了信息,但它破坏了某些东西,Excel根本无法读取它。我使用kdiff来检查任何差异,它声称有很多,但左/右的数据是相同的,想知道这是否与线结束的问题..等等。不是100%确定的。

我检查了斜纹网站上的命令页面,但我不确定如何去做这件事。

回答

2

正如我怀疑这是一个行结束的问题。修改后的twill的save_html函数写成'wb'而不是'w',一切都很好。

+0

使用'twill' Cookie jar获取二进制内容的替代方法'请求':http://stackoverflow.com/questions/37910736/python-twill-download-file-accessible-through-php-script/37911758#37911758 –

相关问题