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 come to know about it. 


We will follow the following steps to write this program:

  1. Read the URL you want to monitor.
  2. Hash the entire website.
  3. Wait for a specified amount of seconds.
  4. If there are any changes as compared to the previous hash notify me else wait and again and then again take the hash.

Libraries required:

Libraries we will be using are:


# Importing libraries
import time
import hashlib
from urllib.request import urlopen, Request
# setting the URL you want to monitor
url = Request('',
              headers={'User-Agent': 'Mozilla/5.0'})
# to perform a GET request and load the
# content of the website and store it in a var
response = urlopen(url).read()
# to create the initial hash
currentHash = hashlib.sha224(response).hexdigest()
while True:
        # perform the get request and store it in a var
        response = urlopen(url).read()
        # create a hash
        currentHash = hashlib.sha224(response).hexdigest()
        # wait for 30 seconds
        # perform the get request
        response = urlopen(url).read()
        # create a new hash
        newHash = hashlib.sha224(response).hexdigest()
        # check if new hash is same as the previous hash
        if newHash == currentHash:
        # if something changed in the hashes
            # notify
            print("something changed")
            # again read the website
            response = urlopen(url).read()
            # create a hash
            currentHash = hashlib.sha224(response).hexdigest()
            # wait for 30 seconds
    # To handle exceptions
    except Exception as e:



Note: time.sleep() takes seconds as a parameter. You can make changes for notification instead of printing the status on the terminal you can write a program to get an email.

Article Tags :