Requests
安装
  
pip install requests
示例
from fake_useragent import UserAgent
import requestsdef cra1_1():
url = 'http://xx/front/website/findAllTypes'
headers = {'User-Agent': UserAgent().chrome}
resp = requests.get(url, headers=headers)
result = resp.json()if __name__ == '__main__':
cra1_1()          发送请求
GET请求
resp = requests.get(url,headers= headers,params=params1) #headers,params1是字典
POST请求
resp = requests.post(url,headers=headers,data=data) #headers,data是字典获取响应信息
获取响应信息
 resp.status_code  获取状态码
 resp.text    获取响应内容 (以字符串)
 resp.json()    获取响应内容【python数据,可直接用jsonpath解析】
 resp.content    获取响应内容(以字节的方式)
 resp.headers    获取响应头内容
 resp.url    获取访问地址
 resp.encoding    获取网页编码
 resp.request.headers    请求头内容
 resp.cookie    获取cookie
         
功能
代理访问
proxies = {"http": "http://10.10.1.10:3128","https": "https://10.10.1.10:1080",}
requests.get("http://www.zhidaow.com", proxies=proxies)
设置超时时间
requests.get('http://github.com', timeout=0.001)
session自动保存cookies
s = requests.Session() # 创建一个session对象
s.get('http://httpbin.org/cookies/set/sessioncookie/123456789') # 用session对象发出get请求,设置cookies
ssl验证
requests.packages.urllib3.disable_warnings() # 禁用安全请求警告
resp = requests.get(url, verify=False, headers=headers)