标签:cookies turn app ike safari main head 字符 os x
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from distutils.log import Log
import requests
import json
from self import self
url = "登录接口"
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 token
if __name__=="__main__":
select_user()
send_post(url)
标签:cookies turn app ike safari main head 字符 os x
原文地址:https://www.cnblogs.com/shengxia0911/p/11072480.html