生活不易 我用python

Requests库里的text和content属性的区别

2017-04-15  本文已影响128人  東飛

官方的文档说明:

>>>>>>>>>>>>>>>>>>>>>>>>>>>  text   <<<<<<<<<<<<<<<<<<<<<<<<<<<
 @property
    def text(self):
        """Content of the response, in unicode."""
                ·········


>>>>>>>>>>>>>>>>>>>>>>>>>>>  content  <<<<<<<<<<<<<<<<<<<<<<<<<<<
@property
    def content(self):
        """Content of the response, in bytes."""
                ·········

例如:

# 下载保存一张图片

# -*- coding:utf-8 -*-
import requests

image_url = 'http://img.infinitynewtab.com/wallpaper/881.jpg'
r = requests.get(image_url)
content = r.content
with open('image.jpg', 'wb') as f:
    f.write(content)

上一篇 下一篇

猜你喜欢

热点阅读