1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| import aiohttp from PIL import Image import asyncio import io import os
headers = {'User-Agent': 'PixivAndroidApp/5.0.191 (Android 6.0.1; HUAWEI ALE-CL00)', 'Accept-Language': 'zh_CN', 'App-OS': 'android', 'App-OS-Version': '6.0.1', 'App-Version': '5.0.191', 'Referer': 'https://www.pixiv.net'}
async def download(url): filename = os.path.basename(url) print(filename) async with aiohttp.ClientSession() as session: async with session.get(url, headers=headers) as resp: print(resp.status) test = await resp.content.read() im = Image.open(io.BytesIO(test)) im.save(filename)
asyncio.run(download('https://i.pximg.net/c/600x1200_90_webp/img-master/img/2017/07/25/21/32/50/64047178_p0_master1200.jpg'))
|
从Pixiv下载的图片用二进制查看是webp格式的,但是后缀名是jpg或者png的,用qqbot发出去的webp格式图片在pcqq上不显示,所以转码一下