Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. async def crawler(loop):
  2.     urls = ...
  3.  
  4.     async with aiohttp.ClientSession(loop=loop) as session:
  5.         for url in urls:
  6.             try:
  7.                 async with session.get(url) as response:
  8.                     image = await response.read()
  9.                     image = Image.open(io.BytesIO(image))
  10.                     image.save(...)
  11.             except Exception:
  12.                 pass
  13.  
  14.  
  15. loop = asyncio.get_event_loop()
  16. loop.run_until_complete(crawler(loop))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement