import requests
import json
#The third step of a reptile
url = 'https://space.bilibili.com/ajax/memeber/GetInfo'
form_data = {'mid':'5860126','csrf':}
headers = {'User-Agent':'Mozilla/5.0(windows NT 6.1;Win64;x64) Applewebkit/537.36 (KHTML,like Gecko) Chrome/70.0.3538.77 Safari/537.36','Referer':'https://space.bilibili.com/5860126/'}
#It's was get's request,now we do a post request
#Need to add request body 'data'
response = requests.post(url,data=form_data,verify=False,headers=headers)
#response.content is a binary type
#String of type string,response.text
#print(response.text)
#The fourth step of a reptile,accurate data acquisition
#Turn 'json' string into a 'python' dictionary and list
#The loads function is the implementation of json string to dictionary
res_dict = json.loads(response.text)
name = res_dict['data']['name']
sex = res_dict['data']['sex']
sign = res_dict['data']['sign']
#The steps 5 of a reptile,save to a database
print(name)
print(sex)
print(sign)
网友评论