python -request类

 

import requests

url='http://www.baidu.com'
params = {"mobilephone":"15814447890","pwd":"123456"}
headers = {"Content-Tpye":"application/x-www-form-urlencoded"} # 指定数据类型,防止中文乱码,加入header 需要把header加入 请求的方法里面

res1 = requests.get(url)
res = requests.post(url,data=params,headers =headers )
# print(res)
r1 = res.status_code # 获取响应码
r2 = res.headers # 获取请求头
r3 = res.text # 获取响应文本 返回的字符串str
r4 = res.json() # 获取json 格式的响应体 返回的字典dict
r5 = res.cookies # 返回cookie
r6 = res.request.url

print(r1)
print(r2)
print(r3)
print(r4)
print("cookies",r5)
print(type(r5))
print(r6)

url1 = "http://www.baidu.com"
param = {"mobilephone":"15810007890", "amount": "50.5"}
param["cookies"] = r5

res = requests.request(method='post',url = url1, data = param)
print(res.status_code)
print(res.text)




















posted @ 2019-09-01 21:35  yago白菜  阅读(431)  评论(0编辑  收藏  举报