post登录资料备份
# coding=utf-8
import urllib
import hashlib
import http.client
import http.cookiejar
import http.cookies #post数据接收和处理的页面(我们要向这个页面发送我们构造的Post数据)
posturl = 'http://xxxxxxxxxxxx/xxxxxx.do' #从提交数据包中分析出,处理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('http://xxxxx.edu.cn/ntms/index.do') #构造header,一般header至少要包含一下两项。这两项是从抓到的包里分析得出的。 headers = {'User-Agent': ' Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': ' zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
# 'Accept-Encoding': 'gzip, deflate',#大坑。加入后要手动对gzip解压后才会有可识别的内容
'Referer': 'http://xxxxx/userlogin.jsp?reason=login',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded',
}
#构造Post数据,也是从抓大的包里分析得出的。 postData = {'j_username': 'xxxxxxxx',
'j_password': 'fc5700426c8d6a74b0cdf987b63922d3', #你的密码,密码可能是明文传输也可能是密文,如果是密文需要调用相应的加密算法加密,需查看js代码
#才知我就直接硬编码了
'save_cookie': 'none'
} #需要给Post数据编码
postData = urllib.parse.urlencode(postData).encode(encoding='UTF-8') #通过urllib.request提供的Request方法来向指定Url发送我们构造的数据,并完成登录过程
request = urllib.request.Request(posturl, postData, headers)
response = urllib.request.urlopen(request)
text = response.read() #测试是否成功登陆,这里是请求用户信息,如果成功登陆,那么cookie发到这个页面之后就会返回用户资料,否则提示错误,也知道自己登陆失败了
headers1 = {'User-Agent': ' Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': ' zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
# 'Accept-Encoding': 'gzip, deflate',#大坑。加入后要手动对gzip解压后才会有可识别的内容
'Referer': 'http://xxxx.edu.cn/ntms/userLogin.jsp?reason=logout',
'Connection': 'keep-alive',
'Content-Length': '',
'Content-Type': ' application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest'
}
request = urllib.request.Request('http://xxxx.edu.cn/action/getCurrentUserInfo.do', None, headers1)
response = urllib.request.urlopen(request)
text = response.read()
#打印回应的内容
print(str(text, encoding='utf-8', errors='strict'))
post登录资料备份的更多相关文章
- 苹果手机 iTunes 资料备份到另一手机
百度教程 https://jingyan.baidu.com/article/d621e8da332e602865913f8e.html 直接使用iTunes将老手机的资料备份, (可能需要关闭手机定 ...
- swift使用查阅资料备份3
自主学习之RxSwift(二) -----flatMap https://blog.csdn.net/chelongfei/article/details/50995603 RxSwift 系列(九) ...
- swift使用查阅资料备份2
Swift3.0朝圣之路-Then协议库-绝妙的初始化方式 https://www.jianshu.com/p/6cc1e21df6ac DisposeBag http://southpeak.git ...
- find tar 压缩第一层目录,用于资料备份。
find *.tar.gz -exec tar zxvf '{}' \;//查找当前目录下的.tar.gz 的文件的 并发送给后面的命令执行find . -maxdepth 1 //查找当前目录下的文 ...
- mysql的登录和备份
mysql -h xxx.xxx.xxx.xxx -u root -p -h 指出服务器名 若是localhost则是指本机 -u 指出用户名 root是默认的最高权限用户名 -p指出密码 不填就指密 ...
- eclipse报错资料备份
一. eclipse中初始化控件出错 在添加 TextView myTextView=(TextView)this.findViewById(R.id.myTextView); Button myBu ...
- 【React 资料备份】React Hook
Hooks是React16.8一个新增项,是我们可以不用创建class组件就能使用状态和其他React特性 准备工作 升级react.react-dom npm i react react-dom - ...
- 【React 资料备份】React v16.3之后的生命周期
React v16.4 的生命周期图 React v16.4 的生命周期 变更缘由 原来(React v16.0前)的生命周期在React v16推出的Fiber之后就不合适了,因为如果要开启asyn ...
- spring 学习资料备份
易百教程 https://www.yiibai.com/spring/spring-autowiring-by-name.html
随机推荐
- 冲刺Offer - 二叉树的深度
https://www.nowcoder.net/practice/435fb86331474282a3499955f0a41e8b?tpId=13&tqId=11191&tPage= ...
- java编程思想-复用类
/* 一个文件中只能有一个public类 并且此public类必须与文件名相同 */ class WaterSource { private String s; WaterSource() { Sys ...
- 001 Cisco router prewired
Cisco router 预配: Router>en Router#config t Enter configuration commands, one per line. End with ...
- NA交换②
虚拟局域网VLAN的核心目的: 将一个大的网络划分为小的网络,也称为网络分片(Segementation):一个VLAN对应着一个广播域,最好对应一个网络子网(为VLAN间的路由作准备). ...
- centos 7 静态IP,指定DNS
cd /etc/sysconfig/network-scripts/ 找到对应的网卡,配置并编辑 ls -l vim ifcfg-em1 配置例子: TYPE="Ethernet" ...
- MariaDB 数据库的备份
1> 备份单个数据库 mysqldump -uroot -plichao123 --database students1 > stundents.sql; 2>查看备份文件 3> ...
- EXISTS 执行顺序 CLR-2-2-引用类型和值类型
EXISTS 执行顺序 select * from a where a.s_status=1 and exists (select orderid from b on a.orderid=b.or ...
- hdu 1258 Sum It Up (dfs+路径记录)
pid=1258">Sum It Up Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- 关于编译(javac),import,package的再理解
1.若我们在A.java中用到了类B,当我们仅仅用 javac A.java 编译A时,编译器也会去寻找B,若类B依然是源文件,也会自动编译它.在使用javac和java命令时,有一个参数选项 -ve ...
- dpdpdpdp~~~!!!
dpdpdpdpdpdp D你妹个P! 妈的劳资就不信征服不了你!!哼!!