Created
April 22, 2017 23:55
-
-
Save diogommartins/a0dd575fc6825e5b8540e84da1fd8759 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 = tuple(get_and_print(session, url) for url in urls) | |
await asyncio.gather(*tasks, return_exceptions=True) | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(fetch(loop, urls)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment