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

时间:2016-11-27 16:41:39

标签: python wget zabbix

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

哪个python库允许我执行“复杂”wget操作?

“复杂”,我的意思是:

 # 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来验证和检索图像。

1 个答案:

答案 0 :(得分:1)

感谢@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!

参考文献: