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

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