python获取请求头里面的cookie
关键方法: python在请求里面放cookies,要在post方法里面 requests.post(URL, DATA, headers=headers,cookies=response.cookies)
def SwitchTest():
url = "https://AABBCC/doLogin"
passwor = hashlib.md5("mima123".encode())
password = passwor.hexdigest()
data = {
"account": "account",
"password": password
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
dataEncode = urllib.parse.urlencode(data).encode('utf-8')
response = requests.post(url, dataEncode, headers=headers)
newData = {
"subjectId": 86
}
checkSubjectURL = "https://AABBCC/user/checkSwitch"
newDataEncode=urllib.parse.urlencode(newData).encode('utf-8')
responseCheckSubject = requests.post(checkSubjectURL, newDataEncode, headers=headers,cookies=response.cookies)
return "responseCheckSubject"
|