python获取请求头里面的cookie
2021-02-13 15:19
标签:course password def pytho cookie style requests get 数学 python获取请求头里面的cookie 标签:course password def pytho cookie style requests get 数学 原文地址:https://www.cnblogs.com/mudingxi/p/12725892.html 1 import requests
2 class ccedu(object):
3 def get_cookie(self):
4 #创建session对象
5 session = requests.Session()
6 url = "http://10.206.14.***:8080/ccsedu/a/login.do"
7 payload = {‘args‘: None, ‘usertype‘:2, ‘username‘:‘********‘, ‘password‘:‘********‘}
8 #使用session发送post请求获取cookie
9 session.post(url,data=payload)
10 print(session.cookies.get_dict())
11 return session.cookies.get_dict()
12 def addteacher(self,name,masterCourse,externalUnit,position):
13 url = "http://10.206.14.***:8080/ccsedu/a/js/jsgl/saveLecturer "
14 payload = {‘name‘: name, ‘sex‘: 1, ‘levels‘: 1, ‘type‘: 2, ‘masterCourse‘: masterCourse,
15 ‘externalUnit‘: externalUnit, ‘position‘: position}
16 res = requests.post(url,data=payload,cookies=c.get_cookie())
17 print(res.json())
18 if __name__ == ‘__main__‘:
19 c = ccedu()
20 c.addteacher("李睿",‘数学‘,‘未知机构‘,‘职务数学老师‘)