哪个 python 库可以执行复杂的 `wget` 操作?

Which python library can perform a complex `wget` operation?

我正在连接到 Zabbix,但由于它没有为我想要的资源之一提供 API,我不得不使用 wget 来完成工作。

哪个 python 库允许我执行 "complex" wget 操作?

"complex," 我的意思是:

 # Logging in to Zabbix
 wget -4 --no-check-certificate --save-cookies=z.coo -4 --keep-session-cookies -O - -S --post-data='name=username&password=somepassword&enter=Sign in&autologin=1&request=' 'https://some.zabbix-site.com:50100/index.php?login=1'

 # Grabbing the network image
 wget -4 --no-check-certificate --load-cookies=z.coo -O result.png 'https://some.zabbix-site.com:50100/map.php?sysmapid=5&severity_min=0'

不确定 requests 是否能完成这项工作?我需要 1) 登录并保存返回的 cookie,2) 使用返回的 cookie 来验证和检索图像。

感谢@ForceBru 的建议。我现在设法找出解决方案!这是:

import requests
s = requests.Session()
data = {'name': 'username', 'password': 'password', 'enter': 'Sign in', 'autologin': '1', 'request': ''}
url = 'https://some.zabbix-site.com:50100/index.php?login=1'
r = s.post(url, data=data)  # use this if the SSL certificate is valid
r = s.post(url, data=data, verify=False)  # use this if the SSL certificate is unsigned
r.cookies  # check the cookies value
re = s.get('https://some.zabbix-site.com:50100/map.php?sysmapid=5&severity_min=0')
re.content  # the file content is here!

参考文献:

  • 详细了解 Requests Session
  • 使用示例Requests to get Cookies
  • 如何获得 file content from Requests