day01
1.requests
install
pip install requests
1.1基础使用
requests模块用于发送网络请求,可以传递参数,自定义标头等
res:object
响应对象
import requests
url = 'https://httpbin.org/get'
res = requests.get(url)
print(res)
get
import requests as req
params = {
"value":"key"
}
url = 'https://httpbin.org/get'
"""
url:请求目标地址
params:get请求携带参数
"""
print(req.get(url,params=params).url)
post
import requests as req
data={
"value":"key"
}
url="https://httpbin.org/post"
print(req.post(url,data=data)).text
cookie
import requests as req
cookies = dict(
key='value'
)
print(req.get('https://httpbin.org/cookies',cookies=cookies)).text
header
import requests as req
url = 'https://httpbin.org/post'
data = {
'key': 'value'
}
header = {
'a': '123'
}
res = req.post(url, data=data, headers=header)
print(res.text)