File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
projects/Time to load Website Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ ## Time to load website
2+
3+ This script takes a url from the user and returns the time taken to load that website.
4+
5+ ## How to use this ?
6+
7+ 1 . Just type the following on the command prompt:
8+
9+ python time_to_load_website.py
10+
11+ 2 . It will reuest you to provide a url. Provide the url and hit enter to see the script in action.
12+
13+ ## Sample use:
14+
15+ <p align = " center " >
16+ <img src="sample.PNG" alt="sample">
17+ </p >
Original file line number Diff line number Diff line change 1+ from urllib .request import urlopen
2+ import time
3+
4+
5+ def get_load_time (url ):
6+ """This function takes a user defined url as input
7+ and returns the time taken to load that url in seconds.
8+
9+ Args:
10+ url (string): The user defined url.
11+
12+ Returns:
13+ time_to_load (float): The time taken to load the website in seconds.
14+ """
15+
16+ if ("https" or "http" ) in url : # Checking for presence of protocols
17+ open_this_url = urlopen (url ) # Open the url as entered by the user
18+ else :
19+ open_this_url = urlopen ("https://" + url ) # Adding https to the url
20+ start_time = time .time () # Time stamp before the reading of url starts
21+ open_this_url .read () # Reading the user defined url
22+ end_time = time .time () # Time stamp after the reading of the url
23+ open_this_url .close () # Closing the instance of the urlopen object
24+ time_to_load = end_time - start_time
25+
26+ return time_to_load
27+
28+
29+ if __name__ == '__main__' :
30+ url = input ("Enter the url whose loading time you want to check: " )
31+ print (f"\n The time taken to load { url } is { get_load_time (url ):.2} seconds." )
You can’t perform that action at this time.
0 commit comments