#!/usr/bin/env python#-*- coding:utf-8 -*-from distutils.log import Logimport requestsimport jsonfrom self import selfurl = "登陸接口"data = { "account": "用戶名", #用戶名 "password": "XXXXXXXX" #密碼}headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"}def send_post(url): aa = requests.post(url=url,data=data,headers=headers) bb = aa.text #輸出接口返回信息 cc = json.loads(bb) #將字符串返回信息轉換成字典 print(cc['data']['id']) #取出字典中某個值的value#獲取登陸用戶的cookie信息def select_user(): session = requests.Session() r = session.post(url=url,headers=headers,data=data) # print(r.text) r.encoding = 'utf-8' cookie = requests.utils.dict_from_cookiejar(session.cookies) token = cookie['token'] return tokenif __name__=="__main__": select_user() send_post(url)