pip install requests
#发送get请求,获取数据
import requests
head = {"User-Agent":"Mozilla/5.0(Windows...."}
res = requests.get(url="https://www.baidu.com",headers=head)
print(res)
print("状态码:",res.status_code)
print(res.text)
print("--------" * 8)
#发送post请求,上传数据
data = {"name":"martin","password":"123456"}
res = requests.post(url="https://www.baidu.com",data=data,headers=head)
print(res.text)
json模块
#作用:处理json格式数据,内置模块
#json ---> 字典; 字典 ---> json
import json
#json.loads()
data_01 = '{"nginx":"1.28","docker":"26.1.4"}'
new_data_01 = json.loads(data_01)
print(new_data_01)
print(type(new_data_01))
print(new_data_01.get("docker"))
print("-------" * 8)
#json.dumps()
data_02 = {"name":"martin","email":"123"}
new_data_02 = json.dumps(data_02)
print(new_data_02)
print(type(new_data_02))