【问题标题】:Python 2.7 using twill, saving downloaded file properlyPython 2.7 使用斜纹,正确保存下载的文件
【发布时间】:2012-10-07 01:53:06
【问题描述】:
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')

这就是我目前正在尝试使用的。

网站是这样工作的:

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

redirect_output 不保存 xls 文件。

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

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

【问题讨论】:

    标签: python twill


    【解决方案1】:

    我怀疑这是一个行尾问题。修改twill的save_html函数写成'wb'而不是'w',一切正常。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    相关资源
    最近更新 更多