python3 requests的content和text方法
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方法的更多相关文章
- python requests的content和text方法的区别(转)
原文地址: http://blog.csdn.net/xie_0723/article/details/51361006 问题: 一直在想requests的content和text属性的区别,从pri ...
- python requests的content和text方法的区别
requests对象的get和post方法都会返回一个Response对象,这个对象里面存的是服务器返回的所有信息,包括响应头,响应状态码等.其中返回的网页部分会存在.content和.text两个对 ...
- python requests的content和text方法的区别【转】
requests对象的get和post方法都会返回一个Response对象,这个对象里面存的是服务器返回的所有信息,包括响应头,响应状态码等.其中返回的网页部分会存在.content和.text两个对 ...
- requests的content与text导致lxml的解析问题
title: requests的content与text导致lxml的解析问题 date: 2015-04-29 22:49:31 categories: 经验 tags: [Python,lxml, ...
- requests的响应返回值显示content和text方法的区别
requests的get或者post请求,返回的响应response获取方法:content和text content用于获取图片,返回二进制数据 text用于获取内容,返回的是unicode解码字符 ...
- python 中爬虫 content和text的区别
一直在想requests的content和text属性的区别,从print 结果来看是没有任何区别 import requests headers = { "User-Agent" ...
- requests方法中content和text区别
requests对象的get和post方法都会返回一个Response对象,这个对象里面存的是服务器返回的所有信息,包括响应头,响应状态码等.其中返回的网页部分会存在.content和.text两个对 ...
- python3+requests:接口自动化测试(二)
转载请注明出处:https://www.cnblogs.com/shapeL/p/9188495.html 前言:上篇文章python3+requests+unittest:接口自动化测试(一):ht ...
- 【python3+request】python3+requests接口自动化测试框架实例详解教程
转自:https://my.oschina.net/u/3041656/blog/820023 [python3+request]python3+requests接口自动化测试框架实例详解教程 前段时 ...
随机推荐
- 自定义C语言CVector
CVector.h // // cvector.h // GKApp // // Created by 王明辉 on 16/4/15. // Copyright (c) 2016年 GK. All r ...
- 【LeetCode】26. Remove Duplicates from Sorted Array 解题报告(Python&C++&Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 [LeetCode] https:// ...
- 【LeetCode】961. N-Repeated Element in Size 2N Array 解题报告(Python & C+++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcod ...
- datatables scrollX设置水平滚动无效问题
如下:设置了水平滚动之后, 页面并没有滚动效果$(document).ready(function() { $('#example').dataTable( { "scrollX" ...
- 51Nod 1279:扔盘子(二分||单调栈)
1279 扔盘子 1.0 秒 131,072.0 KB 5 分 1级题 有一口井,井的高度为N,每隔1个单位它的宽度有变化.现在从井口往下面扔圆盘,如果圆盘的宽度大于井在某个高度的宽度,则圆盘被卡住( ...
- python xlrd读Excel表
1 xlrd第三方库 注意:xlrd较新版本不支持读xlsx表,需安装1.2.0版本(pip install xlrd==1.2.0)或使用其他库. xlrd库官方文档:https://xlrd.re ...
- Nginx 常用配置清单
侦听端口: server {# Standard HTTP Protocollisten 80;# Standard HTTPS Protocollisten 443 ssl;# For http2l ...
- Understanding and Improving Fast Adversarial Training
目录 概 主要内容 Random Step的作用 线性性质 gradient alignment 代码 Andriushchenko M. and Flammarion N. Understandin ...
- Improving Variational Auto-Encoders using Householder Flow
目录 概 主要内容 代码 Tomczak J. and Welling M. Improving Variational Auto-Encoders using Householder Flow. N ...
- <数据结构>XDOJ316.多点测试的写法
问题与解答 问题描述 有一棵无限大的完全二叉树,该二叉树自上而下.自左而右从1开始编号.从某一个结点到根结点(编号是1的结点)都有一条唯一的路径,比如从5到根结点的路径是(5, 2, 1),从4到根结 ...