# -*- coding: utf-8 -*-
"""
@Time : 2024/5/23 14:21
@Author : 娜年花开
@File : 01requests_demo.py
@Desc :
"""
import requests
# 发送百度搜索接口的请求
response = requests.get(url='http://www.baidu.com/s',params={'wd':'python'})
# response = requests.get(url='http://www.baidu.com/s?wd=python')
# 打印响应数据
print(response.text)
# 打印请求的URL
print("请求的URL为:",response.url)
# 打印响应状态码:
print('响应状态码为:',response.status_code)
# 打印cookie
print('百度接口返回的cookie为:',response.cookies)
# 打印响应头
print('百度接口返回的响应头为:',response.headers)
# 打印文本格式响应数据
# print('百度接口返回的文本格式响应数据为:',response.text)print('百度接口返回的文本格式响应数据为:',response.text)
# 打印字节码响应数据
print('字节码数据为:',response.content)
# 字节码数据编码
print('给字节码数据进行编码操作:',response.content.decode(encoding='utf-8'))
# 打印编码
# 打印编码:ISO-8859-1 我们用utf-8解析ISO-8859-1的数据,是无法解析
print('编码为:',response.encoding)
# 打印JSON数据
# 打印规则:首先必须是JSON数据结构才能够打印,如果不是JSON数据结构,会抛出JSONDecodeError错误
# print('Json数据格式为:',response.json())
04-05
312
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-13
3685
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-26
3620
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-25
2601
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-11
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交