python3模拟登录zabbix
2017-03-17 11:03
267 查看
#!/usr/bin/env python # -*- coding: utf-8 -*- import urllib.request import http.cookiejar import urllib.parse # 登录的主页面 hosturl = 'http://xxxxx' # 自己填写 # post数据接收和处理的页面(我们要向这个页面发送我们构造的Post数据) posturl = 'http://xxxxxxxxxxxxxxx/index.php' # 从数据包中分析出,处理post请求的url # 设置一个cookie处理器,它负责从服务器下载cookie到本地,并且在发送请求时带上本地的cookie cj = http.cookiejar.LWPCookieJar() cookie_support = urllib.request.HTTPCookieProcessor(cj) opener = urllib.request.build_opener(cookie_support, urllib.request.HTTPHandler) urllib.request.install_opener(opener) # 打开登录主页面(他的目的是从页面下载cookie,这样我们在再送post数据时就有cookie了,否则发送不成功) h = urllib.request.urlopen(hosturl) # 构造header,一般header至少要包含一下两项。这两项是从抓到的包里分析得出的。 headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0', 'Referer': 'http://xxxxxxxxxxxx/index.php'} # 构造Post数据,他也是从抓大的包里分析得出的。 postData = {"name": 'Admin', "password": 'xxxxxxx', "autologin": 1, "enter": "Sign in"} # 需要给Post数据编码 postData = urllib.parse.urlencode(postData).encode('utf-8') # 通过urllib2提供的request方法来向指定Url发送我们构造的数据,并完成登录过程 request = urllib.request.Request(posturl, postData, headers) response = urllib.request.urlopen(request) text = response.read().decode() print(text)
相关文章推荐
- 使用Python模拟登录QQ邮箱获取QQ好友列表
- Python 模拟登录及表单提交
- 模拟登录新浪微博(Python)
- 【py登陆】python模拟登录
- python模拟登录百度代码分享(获取百度贴吧等级)
- python模拟登录及表单提交
- python模拟登录人人网
- python实现模拟登录
- python模拟登录(一)
- python 模拟登录,使用cookie自动领取下载豆(最新2016)
- Python模拟Web Fetion登录解析
- python模拟浏览器登录淘宝抓取内容
- python实现模拟登录
- 用Python(Tornado)模拟登录小米帐号
- Python网页抓取、模拟登录
- Python网页抓取、模拟登录
- python实现模拟登录
- Python网页抓取、模拟登录
- Python(Tornado)模拟登录小米抢手机
- Python模拟登录百度贴吧