Advertisement
Guest User

Untitled

a guest
Nov 11th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import asyncio
  2. import aiohttp
  3. import time
  4. import requests
  5.  
  6.  
  7. async def parse(url):
  8.     with aiohttp.ClientSession() as session:
  9.         async with session.get(url) as resp:
  10.             main.append(await resp.text())
  11.  
  12.  
  13. main = []
  14. t1 = time.time()
  15. loop = asyncio.get_event_loop()
  16. f = asyncio.wait([parse('https://yandex.ru/search/?text={}'.format(i)) for i in range(100)])
  17. loop.run_until_complete(f)
  18. print(time.time() - t1)
  19. loop.close()
  20.  
  21.  
  22. def req(url):
  23.     a = requests.get(url)
  24.     main2.append(a.text)
  25.  
  26.  
  27. main2 = []
  28. t1 = time.time()
  29. for i in range(100):
  30.     req('https://yandex.ru/search/?text={}'.format(i))
  31. print(time.time() - t1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement