text返回的是Unicode型的数据

content返回的是是二进制的数据。

也就是说,如果你想取文本,可以通过r.text。

如果想取图片,文件,则可以通过r.content

>>> import requests
>>> r = requests.get('https://github.com/timeline.json')
>>> r.text
'{"message":"Hello there, wayfaring stranger. If you’re reading this then you probably didn’t see our blog post a couple of years back announcing that this API would go away: http://git.io/17AROg Fear not, you should be able to get what you need from the shiny new Events API instead.","documentation_url":"https://developer.github.com/v3/activity/events/#list-public-events"}'
>>> r.content
b'{"message":"Hello there, wayfaring stranger. If you\xe2\x80\x99re reading this then you probably didn\xe2\x80\x99t see our blog post a couple of years back announcing that this API would go away: http://git.io/17AROg Fear not, you should be able to get what you need from the shiny new Events API instead.","documentation_url":"https://developer.github.com/v3/activity/events/#list-public-events"}'

例子:

import requests
r = requests.get('http://img2.niutuku.com/1312/0804/0804-niutuku.com-27840.jpg') with open('demo1.jpg', 'wb') as fp:
fp.write(r.content)

参考:

http://cn.python-requests.org/zh_CN/latest/user/quickstart.html#id3

http://blog.csdn.net/xie_0723/article/details/51361006

python3 requests的content和text方法的更多相关文章

  1. python requests的content和text方法的区别(转)

    原文地址: http://blog.csdn.net/xie_0723/article/details/51361006 问题: 一直在想requests的content和text属性的区别,从pri ...

  2. python requests的content和text方法的区别

    requests对象的get和post方法都会返回一个Response对象,这个对象里面存的是服务器返回的所有信息,包括响应头,响应状态码等.其中返回的网页部分会存在.content和.text两个对 ...

  3. python requests的content和text方法的区别【转】

    requests对象的get和post方法都会返回一个Response对象,这个对象里面存的是服务器返回的所有信息,包括响应头,响应状态码等.其中返回的网页部分会存在.content和.text两个对 ...

  4. requests的content与text导致lxml的解析问题

    title: requests的content与text导致lxml的解析问题 date: 2015-04-29 22:49:31 categories: 经验 tags: [Python,lxml, ...

  5. requests的响应返回值显示content和text方法的区别

    requests的get或者post请求,返回的响应response获取方法:content和text content用于获取图片,返回二进制数据 text用于获取内容,返回的是unicode解码字符 ...

  6. python 中爬虫 content和text的区别

    一直在想requests的content和text属性的区别,从print 结果来看是没有任何区别 import requests headers = { "User-Agent" ...

  7. requests方法中content和text区别

    requests对象的get和post方法都会返回一个Response对象,这个对象里面存的是服务器返回的所有信息,包括响应头,响应状态码等.其中返回的网页部分会存在.content和.text两个对 ...

  8. python3+requests:接口自动化测试(二)

    转载请注明出处:https://www.cnblogs.com/shapeL/p/9188495.html 前言:上篇文章python3+requests+unittest:接口自动化测试(一):ht ...

  9. 【python3+request】python3+requests接口自动化测试框架实例详解教程

    转自:https://my.oschina.net/u/3041656/blog/820023 [python3+request]python3+requests接口自动化测试框架实例详解教程 前段时 ...

随机推荐

  1. windows10下vscode+cmake编译Qt5代码

    概述 本文演示环境: windows10 cmake version:3.18 qt version: 5.14 vscode version: 1.54.1 本文演示环境基于在线模式, 离线使用VS ...

  2. 【九度OJ】题目1087:约数的个数 解题报告

    [九度OJ]题目1087:约数的个数 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次 ...

  3. Jenkins安装教程:Windows环境通过jenkins.war安装

    1.Windows操作系统下,安装jdk.tomcat.maven.git,并配置好对应的环境变量,安装教程请自行查询资料 2.将下载的jenkins.war放入到tomcat的webapp文件夹下, ...

  4. linux系统安装java

    1.下载Java压缩包 *.gz 2.解压 3.修改Linux配置文件,配置Java环境变量 4.使用命令source /etc/profile让修改生效 转载 https://www.cnblogs ...

  5. CS5211替代CH7511B|设计DP转LVDS转接板|替代CH7511B

    CH7511B是一款DP转lvds屏转换芯片CH7511B是一款eDP转LVDS转换芯片.CH7511B将嵌入式DisplayPort信号转换为LVDS(低压差分信号).通过CH7511B的高级解码/ ...

  6. Java程序设计基础笔记 • 【第4章 条件结构】

    全部章节   >>>> 本章目录 4.1 条件结构 4.1.1 程序流程控制 ​4.1.2 单分支if结构 4.1.3 双分支if结构 4.1.4 实践练习 4.2 多重条件结 ...

  7. docker学习:docker命令

    帮助命令 自验证 docker version 详情信息 docker info 获取帮助 docker --help 镜像命令 列出本例主机上的镜像 docker images [OPTIONS] ...

  8. MyBatis 一级缓存实现详解及使用注意事项

    一级缓存介绍 在应用运行过程中,我们有可能在一次数据库会话中,执行多次查询条件完全相同的SQL,MyBatis提供了一级缓存的方案优化这部分场景,如果是相同的SQL语句,会优先命中一级缓存,避免直接对 ...

  9. CSS基础 阴影相关属性设置

    一.字体阴影属性名:text-shadow:水平偏移量 垂直偏移量 模糊度 阴影颜色: html代码: <div>农夫山泉有点甜</div>css代码: div{ font-s ...

  10. Python基础案例练习:制作学生信息管理系统

    一.前言 学生信息管理系统,相信大家或多或少都有做过 最近看很多学生作业都是制作一个学生信息管理系统 于是,今天带大家做一个简单的学生信息管理系统 二.开发环境: 我用到的开发环境 Python 3. ...