-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeasure_load_time.py
executable file
·35 lines (27 loc) · 1014 Bytes
/
measure_load_time.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
import sys
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def measure_load_time(url):
# Set up the WebDriver (Chrome in this example)
options = webdriver.ChromeOptions()
options.add_argument("--headless") # Run headless Chrome
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=options)
# Measure the page load time
start_time = time.time()
driver.get(url)
end_time = time.time()
load_time = end_time - start_time
print(f"Page load time for {url}: {load_time:.2f} seconds")
# Close the browser
driver.quit()
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python measure_load_time.py <url>")
sys.exit(1)
url = sys.argv[1]
measure_load_time(url)