Skip to content

Instantly share code, notes, and snippets.

@diogommartins
Created April 22, 2017 23:57
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/e13c302779efd8cb954100c665f1d103 to your computer and use it in GitHub Desktop.
Save diogommartins/e13c302779efd8cb954100c665f1d103 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 = (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