Skip to content

Instantly share code, notes, and snippets.

@diogommartins
Created April 22, 2017 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogommartins/a0dd575fc6825e5b8540e84da1fd8759 to your computer and use it in GitHub Desktop.
Save diogommartins/a0dd575fc6825e5b8540e84da1fd8759 to your computer and use it in GitHub Desktop.
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