token登录处理
#coding:utf-8
import requests
class operation_header:
#获取登录的token
def login(self):
url = "XXXX/login"
data = {
"account": "xxx",
"password": "xxxxx",
"domainNumber": xxx
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded'
}
r = requests.post(url, data=data, headers=headers).json()
token=r['data']['token']
return token
if __name__ == '__main__':
ope=operation_header()
token=ope.login()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded'
}
url1="XXXXX"
#添加token到header
headers['Authorization'] = token
s=requests.session()
r1=s.get(url1,headers=headers).json()
print(r1)