python requests的content和text方法的区别
来源:互联网 发布:linux groupadd 编辑:程序博客网 时间:2024/05/29 15:19
一直在想requests的content和text属性的区别,从print 结果来看是没有任何区别
@property def text(self): """Content of the response, in unicode. If Response.encoding is None, encoding will be guessed using ``chardet``. The encoding of the response content is determined based solely on HTTP headers, following RFC 2616 to the letter. If you can take advantage of non-HTTP knowledge to make a better guess at the encoding, you should set ``r.encoding`` appropriately before accessing this property. """ #content的完整代码就不贴了。 @property def content(self): """Content of the response, in bytes."""结论是:text 返回的是unicode 型的数据,一般是在网页的header中定义的编码形式。
content返回的是bytes,二级制型的数据。
也就是说你如果想要提取文本就用text
但是如果你想要提取图片、文件,就要用到content
举例说明:
# 例如下载并保存一张图片import requestsjpg_url = 'http://img2.niutuku.com/1312/0804/0804-niutuku.com-27840.jpg'content = requests.get(jpg_url).contentwith open('demo.jpg', 'wb') as fp: fp.write(content)
阅读全文
0 0
- python requests的content和text方法的区别
- python requests的content和text方法的区别
- python requests的content和text方法的区别(转)
- python requests 详细学习content 和text 的区别
- python3 requests的content和text方法
- 爬虫学习01 requests入门 response的常用方法 response.text 和response.content的区别
- text和content方法的区别
- python response.text和response.content的区别
- Python 中requests 模块text 和content 差别
- python requests的方法
- requests的content与text导致lxml的解析问题
- requests的content与text导致lxml的解析问题
- Python的requestcontent和text的区别
- python下requests模块的安装方法
- MVC中Href方法和Url.Content()方法的区别
- python requests模块的安装和使用方法
- requests和bs4的python爬虫入门
- python的requests库
- 样本册的制作思路设计
- openwrt入门第一天
- C#委托
- log4j只输出指定类的日志到某个文件
- Android 自定义EditText清除功能输入
- python requests的content和text方法的区别
- LinearLayout中使每个子控件均匀布局
- 月薪3万的程序员都避开了哪些坑
- Hadoop集群安装
- 内存溢出和内存泄漏的区别、产生原因以及解决方案
- iscsi target tgt架构
- mysql存储过程书写
- 机器学习(3)强化学习の入门
- 模拟登陆校园网获得学生成绩数据