shell

python requests下载图片

# 文件下载方法
from urllib.request import urlretrieve
import requests

# 第一
urlimage  = 'https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz'
urlretrieve(urlimage, "logo.tar.xz")

#第二
ir = requests.get(urlimage, stream=True)
print (ir.status_code)
if ir.status_code == 200:
    with open('logo2.tar.xz', 'wb') as f:
        for chunk in ir:
            f.write(chunk)


#第三
ir = requests.get(urlimage)
print (ir.status_code)
if ir.status_code == 200:
    with open('logo3.tar.xz', 'wb') as f:
        f.write(ir.content)

 

posted @ 2018-06-07 17:40  devops运维  阅读(1231)  评论(0编辑  收藏  举报
python