多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
**发送简单的请求:** ```python response = requests.get(url) response的常用方法: response.text response.content response.status_code # 响应状态码,返回200则表示请求成功 response.request.headers response.headers ``` <br/> **`response.text`和`response.content`的区别:** ```python response.text 类型:str 修改编码方式:response.encoding='utf-8' 获取网页编码:response.encoding response.content 类型:bytes,即字节数据 修改编码方式:response.content.decode('utf-8') 将字节转换为字符串:response.content.decode() ``` <br/> **案例:下载图片** ```python import requests response = requests.get('https://www.baidu.com/img/bd_logo1.png?where=su') with open('E:/python/baidu.png', 'wb') as f: f.write(response.content) ```