黑松山资源网 Design By www.paidiu.com
早就听说requests的库的强大,只是还没有接触,今天接触了一下,发现以前使用urllib,urllib2等方法真是太搓了……
这里写些简单的使用初步作为一个记录
本文继续练习使用requests登录网站,人人影视有一项功能是签到功能,需要每天登录签到才能升级。
下面的代码python代码实现了使用requests登录网站的过程。
以下是使用fiddler抓包得到完整的HTTP请求头:
POST http://www.zimuzu.tv/User/Login/ajaxLogin HTTP/1.1 Host: www.zimuzu.tv Connection: keep-alive Content-Length: 102 Accept: application/json, text/javascript, */*; q=0.01 Origin: http://www.zimuzu.tv X-Requested-With: XMLHttpRequest User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36 Content-Type: application/x-www-form-urlencoded DNT: 1 Referer: http://www.zimuzu.tv/user/login Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.8,en;q=0.6 Cookie: PHPSESSID=st40f3vohv6q16ec3atekimba0; last_item:10733=Game.of.Thrones.S06E01.The.Red.Woman.1080p.WEB-DL.DD5.1.H.264-NTb.mkv; last_item_date:10733=1461856566; mykeywords=a%3A2%3A%7Bi%3A0%3Bs%3A6%3A%22%E7%A1%85%E8%B0%B7%22%3Bi%3A1%3Bs%3A14%3A%22Silicon+Valley%22%3B%7D; zmz_rich=2 account=你的用户名&password=你的密码&remember=1&url_back=http%3A%2F%2Fwww.zimuzu.tv%2Fuser%2Fsign
python3使用requests登录人人影视网站.py代码:
""" python3使用requests登录人人影视网站.py 2016年5月11日 07:33:59 codegay 参考资料requests文档: http://cn.python-requests.org/zh_CN/latest/ 四种常见的 POST 提交数据方式 https://imququ.com/post/four-ways-to-post-data-in-http.html """ import re import requests #requests 安装命令:pip install requests loginurl='http://www.zimuzu.tv/User/Login/ajaxLogin' surl='http://www.zimuzu.tv/user/sign' httphead={ 'Accept':'application/json, text/javascript, */*; q=0.01', 'Origin':'http://www.zimuzu.tv', 'X-Requested-With':'XMLHttpRequest', 'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded', } data="account=用户名&password=密码&remember=1" session=requests.Session() login=session.post(loginurl,data=data,headers=httphead) print(login.cookies)#打印登录后取得到cookies对象 print(login.json()) getstat=session.get(surl).text.split("\n") #访问签到页面,显示最近三次登录时间 [print(r) for r in getstat if "三次登录时间" in r]
对比其中两者可见,有一些HTTP头省略掉也能达到目的,毕竟每次手动请求头感觉挺麻烦的。
在fidder 中Connection: keep-alive Content-Length: 两项不能省略,ncat之类的工具中也不能省略Content-Length,如果改动了post的数据,需要手动修正Content-Length的值。
在python中可以省略掉Content-Length,我猜python已经帮我们处理了。
关于python3使用requests登录人人影视网站的方法就给大家介绍这么多,希望对大家有所帮助!
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- s14全球总决赛瑞士轮什么时候开始 s14瑞士轮开始时间介绍
- 晨报|《使命召唤21》全球发布预告 《异形:隔离》续作官宣开发中
- 隐形女联动毁灭博士?杰西卡·阿尔巴与小唐尼晒合影
- 《博德之门3》7号补丁发布后:Mod下载量达到2200万次!
- 徐璨宾《井底的蚯蚓》[FLAC/分轨][218.37MB]
- 王冰冰《Vaga Luna 月球漫游》[320K/MP3][62.76MB]
- 证声音乐图书馆《蔚蓝海岸·爵士度假日》[320K/MP3][59.79MB]
- 群星.1993-飞图合唱歌曲精丫飞图】【WAV+CUE】
- 王霏霏.2024-TOOOOO.BUSY(EP)【SNMUSIC】【FLAC分轨】
- 张宇.2016-好男人的情歌NEWXRCD【金牌大风】【WAV+CUE】
- 《食戟之灵》小林龙胆兔女郎比基尼版模型即将发售
- 重大里程碑!九号电动第500万台智能两轮电动车正式下线
- TGA主持人发文祝贺《暗喻幻想》 国外网友:提名稳了?
- 【原神】V5.0攻略 | 旋曜玉帛收集攻略(序号81~序号90)
- 【原神】V5.0攻略 | 旋曜玉帛收集攻略(序号91~序号100)