欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python3使用requests登錄人人影視網(wǎng)站的方法

 更新時間:2016年05月11日 11:06:09   作者:codegay  
通過本文給大家介紹python代碼實(shí)現(xiàn)使用requests登錄網(wǎng)站的過程。非常具有參考價值,感興趣的朋友一起學(xué)習(xí)吧

早就聽說requests的庫的強(qiáng)大,只是還沒有接觸,今天接觸了一下,發(fā)現(xiàn)以前使用urllib,urllib2等方法真是太搓了……

這里寫些簡單的使用初步作為一個記錄

本文繼續(xù)練習(xí)使用requests登錄網(wǎng)站,人人影視有一項(xiàng)功能是簽到功能,需要每天登錄簽到才能升級。

下面的代碼python代碼實(shí)現(xiàn)了使用requests登錄網(wǎng)站的過程。

以下是使用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登錄人人影視網(wǎng)站.py代碼:

"""
python3使用requests登錄人人影視網(wǎng)站.py
2016年5月11日 07:33:59 codegay
參考資料requests文檔:
http://cn.python-requests.org/zh_CN/latest/
四種常見的 POST 提交數(shù)據(jù)方式
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頭省略掉也能達(dá)到目的,畢竟每次手動請求頭感覺挺麻煩的。

在fidder 中Connection: keep-alive Content-Length: 兩項(xiàng)不能省略,ncat之類的工具中也不能省略Content-Length,如果改動了post的數(shù)據(jù),需要手動修正Content-Length的值。

在python中可以省略掉Content-Length,我猜python已經(jīng)幫我們處理了。

關(guān)于python3使用requests登錄人人影視網(wǎng)站的方法就給大家介紹這么多,希望對大家有所幫助!

相關(guān)文章

最新評論