Created
April 22, 2017 23:57
-
-
Save diogommartins/e13c302779efd8cb954100c665f1d103 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from aiohttp import ClientSession | |
urls = ( | |
'http://www.americanas.com', | |
'http://www.submarino.com', | |
'http://www.shoptime.com', | |
'http://www.soubarato.com', | |
) | |
async def get_and_print(session, url): | |
async with session.get(url) as response: | |
print(await response.text()) | |
async def fetch(loop, urls): | |
async with ClientSession(loop=loop) as session: | |
tasks = (get_and_print(session, url) for url in urls) | |
await asyncio.gather(*tasks, return_exceptions=True) | |
loop.stop() | |
loop = asyncio.get_event_loop() | |
loop.create_task(fetch(loop, urls)) | |
loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment