【发布时间】:2020-07-14 17:14:37
【问题描述】:
我是异步的新手。
所以,我的目标是从事件循环中获得一系列响应。毕竟我真的不明白这个return html_text 去了哪里。
能否请您更正我的代码或提供替代解决方案?
urls = [https://www.google.com, https://www.youtube.com/]
async def r_get(url):
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=headers) as resp:
resp.encoding = 'utf-8'
html_text = await resp.text())
return html_text
urls = [asyncio.ensure_future(r_get(url)) for url in urls_with_id]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*urls))
【问题讨论】:
标签: asynchronous async-await python-asyncio