从提交按钮请求python获取下载的文件

时间:2019-06-26 16:01:15

标签: python python-requests

我想从电缆调制解调器本地保存配置文件。我已经登录到调制解调器的html管理页面,并且在备份页面中,有一个按钮可以备份配置文件。事件内部,表单上有一个 POST 方法,该方法可引至下一个URL:

https://192.168.1.1/goform/BackUp

响应头为:

HTTP/1.0 200 OK
Server: GoAhead-Webs
Pragma: no-cache
Cache-control: no-cache
Content-Type: application/download 
Content-Disposition: attachment; filename=cmconfig.cfg // This is the file that is downloaded when I click in the BackUp button

这是我传递给 POST 函数的参数:

dir: admin/
file: cmconfig.cfg

到目前为止,我有以下代码:

with requests.Session() as s:  # To login into the modem
    pagePostBackUp = 'https://192.168.1.1/goform/BackUp'
    s.post(urlLogin, data=loginCredentials, verify=False, timeout=5)
    dataBackUp = {'dir': 'admin/','file': 'cmconfig.cfg'}
    resultBackUp = s.post(pagePostBackUp, data=dataBackUp, verify=False, timeout=10)

cmconfig.cfg文件本地保存的下一行是什么?

1 个答案:

答案 0 :(得分:1)

您的resultBackUpa response object,因此您可以使用其textjson方法。

print(resultBackUp.text)