Python aiohttp简单入门

import aiohttp
import asyncio


async def fetch(session, url):
    async with session.get(url) as response:
        return await response.read()


async def main(URL):
    async with aiohttp.ClientSession() as session:
        for url in URL:
            html = await fetch(session, url)
            with open('./%s' % url.split('/')[-1].split('?')[0], 'wb') as f:
                f.write(html)


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    jpg_ = ['https://iterm2.com/downloads/stable/iTerm2-3_3_6.zip']
    loop.run_until_complete(main(jpg_))

发布了139 篇原创文章 · 获赞 24 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/mbh12333/article/details/103722240
今日推荐