python 비동기 http

.·2023년 5월 4일
0
import asyncio
import aiohttp

data = {}


def async_requests(url_lst, params=None):
    async def get_html(url, params):
        async with aiohttp.ClientSession() as session:
            async with session.get(url) as response:
                data[params] = await response.json()

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        asyncio.gather(*(get_html(url_lst[i], params[i]) for i in range(len(url_lst))))
    )

    return data
profile
.

0개의 댓글