下载图片

requests

import requests
import time

response = requests.post('http://kq.neusoft.com/imageRandeCode')
now = time.time()
with open('%s.jpg' % now, 'wb') as file:
    file.write(response.content)

urllib

from urllib import request

request.urlretrieve('http://kq.neusoft.com/imageRandeCode', '%s.jpg' % now)

PIL(Pillow)

import requests
from PIL import Image

''' ===== bytes-like object === '''
# 二元组
size = 50, 15
response = requests.post('http://www.xxx.com/imageRandeCode')
img = Image.frombytes('RGB', size, response.content)
img.save('%s.jpg' % now, 'JPG')

''' ===== file-like object ===== '''
response = requests.post('http://www.xxx.com/imageRandeCode')
# io.BytesIO() convert the bytes-like object containing the encoded image to file-like object
img = Image.open(io.BytesIO(response.content))
img.save('%s.jpg' % now, 'JPG')

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,一毛也是爱

打开支付宝扫一扫,即可进行扫码打赏哦