You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cpr_trafficscript2.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. from selenium import webdriver
  3. from selenium.webdriver.chrome.service import Service as ChromeService
  4. from selenium.webdriver.chrome.options import Options
  5. from webdriver_manager.chrome import ChromeDriverManager
  6. import time
  7. # Function to prompt user for user ID
  8. def get_user_id():
  9. return input("Please enter your user ID: ")
  10. # Set up Chrome options
  11. chrome_options = Options()
  12. chrome_options.add_argument("--headless") # Run headless Chrome, comment out if you want to see the browser
  13. # Use WebDriverManager to automatically use the system's ChromeDriver
  14. service = ChromeService(ChromeDriverManager().install())
  15. driver = webdriver.Chrome(service=service, options=chrome_options)
  16. # Prompt user for user ID
  17. user_id = get_user_id()
  18. # List of paths to test
  19. paths = ['/', '/shop/', '/product/blue-sweater/', '/product/custom-tee/', '/product-category/clothing/dresses/']
  20. # Base URL
  21. base_url = f'http://{user_id}.cpr-akashop.com'
  22. # Function to measure load time
  23. def measure_load_time(url):
  24. start_time = time.time()
  25. driver.get(url)
  26. # Wait for the page to completely load (adjust as necessary)
  27. time.sleep(5) # Simple wait; use WebDriverWait for more precise control
  28. end_time = time.time()
  29. return end_time - start_time
  30. # Test each path
  31. for path in paths:
  32. full_url = base_url + path
  33. load_time = measure_load_time(full_url)
  34. print(f"Load time for {full_url}: {load_time:.2f} seconds")
  35. # Close the driver
  36. driver.quit()