# 导包
import requests

# 发送百度请求
responseValue = requests.get(url="http://www.baidu.com/")

# 获取请求响应状态码
print("响应状态码:", responseValue.status_code)

# 获取请求URL
print("请求URL:", responseValue.url)

# 获取响应字符编码
print("响应字符编码:", responseValue.encoding)

# 获取响应头数据
print("响应头信息:", responseValue.headers)
print("响应头中的congtent-type:", responseValue.headers.get("Content-Type"))

# 获取响应头的cookie信息
print("响应中的cookie:", responseValue.cookies)
print("提取响应信息中cookie中的BDORZ:", responseValue.cookies.get("BDORZ"))

# 获取文本形式的响应内容
print("文本形式显示响应内容:", responseValue.text)

# 获取字节形式的响应内容,会将汉字转换成二进制码(主要用来传递图片、视频、文件时候用到)
print("获取字节行是的响应内容:", responseValue.content)

#获取字节形式的相应内容并用utf-8格式来解码
print("获取字节行是的响应内容:", responseValue.content.decode("utf-8"))

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐