在某些情况下来说,response.text 与 response.content 都是来获取response中的数据信息,效果看起来差不多。那么response.text 和 response.content 到底有哪些差别 ? 什么情况下该用 response.text 什么情况下该用 response.content ?

  • 返回的数据类型

    response.text 返回的是一个 unicode 型的文本数据

    response.content 返回的是 bytes 型的二进制数据

    也就是说如果想取文本数据可以通过response.text 如果想取图片,文件,则可以通过 response.content

  • 数据编码

    response.content 返回的是二进制响应内容

    response.text 则是默认”iso-8859-1”编码,服务器不指定的话是根据网页的响应来猜测编码。

response.text与content的区别的更多相关文章

  1. requests中text和content的区别

    # -*- coding: utf-8 -*- __author__ = "nixinxin" import re img_url = "https://f11.baid ...

  2. python response.text和response.content的区别

      1.重点理解 response.text返回的类型是str response.content返回的类型是bytes,可以通过decode()方法将bytes类型转为str类型 推荐使用:respo ...

  3. pyhon-request之repsonse的常用方法reponse.text和reponse.content的区别

    1. requests在python2 和 python3中通用,方法完全一样 2. request简单易用 requests的作用 作用:发送网络请求,返回响应数据 用法 response = re ...

  4. scrapy中response.body 与 response.text区别

    scrapy中response.body 与 response.text区别 body http响应正文, byte类型 text 文本形式的http正文,str类型,它是response.body经 ...

  5. requests中 .text 和 .content区别

    import requests url = 'https://www.baidu.com' response = requests.get(url) 1.response.content: 这个是直接 ...

  6. Python获取爬虫数据, r.text 与 r.content 的区别

    1.简单粗暴来讲: text 返回的是unicode 型的数据,一般是在网页的header中定义的编码形式. content返回的是bytes,二级制型的数据. 如果想要提取文本就用text 但是如果 ...

  7. java web 中有效解决中文乱码问题-pageEncoding与charset区别, response和request的setCharacterEncoding 区别

    这里先写几个大家容易搞混的编码设置代码: 在jsp代码中的头部往往有这两行代码 pageEncoding是jsp文件本身的编码contentType的charset是指服务器发送给客户端时的内容编码J ...

  8. Request库使用response.text返回乱码问题

    我们日常使用Request库获取response.text,这种调用方式返回的text通常会有乱码显示: import requests res = requests.get("https: ...

  9. response.getWriter().write()和 response.getWriter().print()的区别 以及 PrintWriter对象 和 out对象 的区别

    感谢原文作者:krismile__qh 原文链接:https://blog.csdn.net/krismile__qh/article/details/89926001 一.response.getW ...

随机推荐

  1. assignment of day four

    目录 1.Numeric type (1)integer (2)float Usefulness Define How to use 2.string type Use Define How to u ...

  2. 第九篇 数据表设计和保存item到json文件

    上节说到Pipeline会拦截item,根据设置的优先级,item会依次经过这些Pipeline,所以可以通过Pipeline来保存文件到json.数据库等等. 下面是自定义json #存储item到 ...

  3. HTML5 Canvas知识点学习笔记

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/huangyibin628/article/details/30108165 canvas ① 主要作 ...

  4. 22-8-filter

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. boost 大小端转换

    boost 中有一个edmian 里面有转换函数模板 native_to_little<T> 本地转换为小端 native_to_bit<T> 本地转换为大端

  6. easyui 弹出框调用外部js函数 提示“Microsoft JScript 运行时错误: 缺少对象”

    昨天遇见一个很诡异的问题 我用easyui做了一个网站,其中有一个a页面和一个b页面,我通过easyui的window功能,在a页面中弹出了一个b页面,在b页面中,我用到了一个外部js的函数c,我在b ...

  7. MapReduce分区数据倾斜

    什么是数据倾斜? 数据不可避免的出现离群值,并导致数据倾斜,数据倾斜会显著的拖慢MR的执行速度 常见数据倾斜有以下几类 1.数据频率倾斜   某一个区域的数据量要远远大于其他区域 2.数据大小倾斜  ...

  8. QueryList 内容过滤

    <?php require 'vendor/autoload.php'; use QL\QueryList; $html =<<<STR <div id="de ...

  9. PHP setrawcookie() 函数

    定义和用法 setrawcookie() 函数不对 cookie 值进行 URL 编码,发送一个 HTTP cookie. cookie 是由服务器发送到浏览器的变量.cookie 通常是服务器嵌入到 ...

  10. spark集群进入 bin 下面目录./spark-shell 出现Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

    spark集群启动的时候可以正常,进入 ./spark-shell 就会出现如下错误 配置文件:spark-env.sh export JAVA_HOME=/usr/java/jdk1.7.0_51e ...