Advertisement
dereksir

Untitled

Nov 22nd, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import aiohttp
  2. import asyncio
  3. import time
  4.  
  5. async def main():
  6.     url = "https://scrapeme.live/shop/"
  7.  
  8.     # Time Tracking: Start Time
  9.     start_time = time.time()
  10.  
  11.     # Fetching content asynchronously
  12.     content = await fetch(url)
  13.  
  14.     # Printing content
  15.     print(content)
  16.  
  17.     # Time Tracking: End Time
  18.     end_time = time.time()
  19.  
  20.     # Calculating and printing the time taken
  21.     print(f"Time taken: {end_time - start_time} seconds")
  22.  
  23. async def fetch(url):
  24.     # Create HTTP session
  25.     async with aiohttp.ClientSession() as session:
  26.         # Make GET request using session
  27.         async with session.get(url) as response:
  28.             # Return text content
  29.             return await response.text()
  30.  
  31. # Run the main function
  32. asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement