/* 时间:2020/10/23 功能:参数标记 目录: 一: 头部信息 二: 请求参数 三: 返回参数 */
一: 头部信息
警告: import urllib3 urllib3.disable_warnings() # 忽略警告
二: 请求参数
请求: 1 get请求: requests.get(url, headers=header, params=par, verify=False) 2 post请求: (1) application/x-www-form-urlencoded (a) requests.post(url, headers=header, params/body=par, verify=False) (2) json (a) requests.post(url, headers=header, json=body, verify=False) (b) import json r = requests.post(url, headers=header, data=json.dumps(body), verify=False)
参数: url # url headers # 头部信息 cookies # cook params # 参数 body # 参数 - body json # 参数 - json verify=False # 抓包警告 allow_redirects = False # 禁止重定位 data=json.dumps(body) data=body.encode("utf-8") # 遇到编码报错时候,对body进行encode
三: 返回参数
r常用 print(r.status_code) # 状态码 print(r.headers) # 头部信息 - 字典存储 print(r.text) # 正文 - 未解码 print(r.content.decode("utf-8")) # 正文 - 解码 print(r.json()) # requests内置json解码器,把json转换dict print(r.encoding) # 编码 print(r.url) # url地址 print(r.cookies) # cookies信息 print(r.content) # 字节输出 print(r.text) # str输出 print(r.json()) # 字典格式