网页前端开发网站,广州花都区网站建设,中国建设银行企业门户网站,不同用户入口的网站样板在Python中#xff0c;requests库是一个常用的HTTP请求库#xff0c;用于发送各种类型的HTTP请求。 以下是一些基本的用法#xff1a; 更多高级功能可以参考官方文档#xff1a;https://docs.python-requests.org/
发送GET请求
response requests.get(https://www.examp…在Python中requests库是一个常用的HTTP请求库用于发送各种类型的HTTP请求。 以下是一些基本的用法 更多高级功能可以参考官方文档https://docs.python-requests.org/
发送GET请求
response requests.get(https://www.example.com)
print(response.text)发送POST请求
data {key: value}
response requests.post(https://www.example.com, datadata)
print(response.text)发送带参数的GET请求
params {key1: value1, key2: value2}
response requests.get(https://www.example.com, paramsparams)
print(response.url)
print(response.text)获取响应状态码和响应头
response requests.get(https://www.example.com)
print(response.status_code)
print(response.headers)处理JSON数据
response requests.get(https://api.github.com/users/octocat)
json_data response.json()
print(json_data[login])超时设置
response requests.get(https://www.example.com, timeout5)
print(response.text)