房地产开发公司网站建设方案,cms模板下载,天津市住房和城乡建设厅官网,24视频网站建设在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)