How to Check Loading Time of Website using Python
Last Updated :
11 Jul, 2022
In this article, we will discuss how we can check the website's loading time.
Do you want to calculate how much time it will take to load your website? Then, what you must need to exactly do is subtract the time obtained passed since the epoch from the time obtained after reading the whole website.
Stepwise Implementation:
Step 1: Import the libraries
In this step, we are simply importing the required libraries to the working python environment to use its functionalities further as per needed.
Here, we are importing the urllib.request and time libraries, the urllib.request library defines functions and classes which help in opening URLs, while the time library defines the time which helps in returning the number of seconds passed since the epoch.
from urllib.request import urlopen
from time import time
Step 2: Obtain the website
In this step, we have used the urlopen() function in which we have to pass the URL of the website as an argument for obtaining the website.
website = urlopen('#Url of the website')
Step 3: Return the time passed since the epoch
In this step, we have used the function time() which will return the number of seconds passed since the epoch.
open_time = time()
Step 4: Read the entire website
In this step, we will use the read() function which will read the contents of the entire file.
output = website.read()
Step 5: Return the time passed since the epoch
In this step, we have used the function time() which will return the number of seconds passed since the epoch.
close_time = time()
Step 6: Close the website
In this step, we have used the close() function that closes the opened file.
website.close()
Step 7: Subtract the time obtained passed since the epoch from the time obtained after reading the whole website
In this step, we will subtract the time obtained passed since the epoch from the time obtained after reading the whole website.
print('The loading time of website is',round(close_time-open_time,3),'seconds')
Example:
Python3
# Python program to check the
# loading time of the website
# Importing the libraries
from urllib.request import urlopen
from time import time
# Obtaining the URL of website
website = urlopen('https://www.geeksforgeeks.org/')
# Return the number of seconds
# passed since epoch
open_time = time()
# Read the complete website
output = website.read()
# Return the number of seconds
# passed since epoch
close_time = time()
# Close the website
website.close()
# Subtract and print the open time
# of website from close time
print('The loading time of website is',round(close_time-open_time,3),'seconds')
Output:
Similar Reads
How to check whether users internet is on or off using Python? Many times while developing our projects we require a solution for checking whether the user system's internet is on or off below are some simple solutions for checking that using Python. Using httplib to check whether users internet is on or off We imported http.client library. Initialized URL as w
3 min read
How to check horoscope using Python ? In this article, we are going to see how to get a horoscope a day before, on that day as well as the day after using Beautifulsoup. Module needed:bs4: Beautiful Soup(bs4) is a Python library for pulling data out of HTML and XML files. This module does not come built-in with Python. To install this t
4 min read
Downloading files from web using Python Requests is a versatile HTTP library in python with various applications. One of its applications is to download a file from web using the file URL. Installation: First of all, you would need to download the requests library. You can directly install it using pip by typing following command: pip ins
4 min read
Python script to monitor website changes In this article, we are going to discuss how to create a python script to monitor website changes. You can code a program to monitor a website and it will notify you if there are any changes. This program has many useful scenarios for example if your school website has updated something you will com
3 min read
Building CLI to check status of URL using Python In this article, we will build a CLI(command-line interface) program to verify the status of a URL using Python. The python CLI takes one or more URLs as arguments and checks whether the URL is accessible (or)not. Stepwise ImplementationStep 1: Setting up files and Installing requirements First, cr
4 min read
Website Blocker Using Python This is real world program which blocks certain distracting website like Facebook, Youtube etc during your work hours. About the program : What we are going to in this program is that we will pass the link of websites which you think is distracting and the time that you are working on your computer
3 min read
Non blocking wait in selenium using Python Prerequisite : Browser Automation Using SeleniumWhen we want to do web automation, we require to wait for some javascript elements to load before we perform some action. For that matter, generally people use Python3 time.sleep(in_seconds) which is a blocking call.By blocking call I mean, it waits or
3 min read
Extract title from a webpage using Python Prerequisite Implementing Web Scraping in Python with BeautifulSoup, Python Urllib Module, Tools for Web Scraping In this article, we are going to write python scripts to extract the title form the webpage from the given webpage URL. Method 1: bs4 Beautiful Soup(bs4) is a Python library for pulling
3 min read
How to get current_url using Selenium in Python? While doing work with selenium many URL get opened and redirected in order to keeping track of URL current_url method is used. The current_url method is used to retrieve the URL of the webpage the user is currently accessing. It gives the URL of the current webpage loaded by the driver in selenium.
2 min read
How to scrape the web with Playwright in Python In this article, we will discuss about Playwright framework, Its feature, the advantages of Playwright, and the Scraping of a basic webpage. The playwright is a framework for Web Testing and Automation. It is a fairly new web testing tool from Microsoft introduced to let users automate webpages more
3 min read