Welcome folks today in this blog post we will be monitoring website changes
and this python script will update you whenever the content of the website has been changed. All the source code of the application is shown below.
Libraries Used
time
library is used for waiting or adding delay in python application
hashlib
It is a built in python library for hashing the content of the entire website
urllib
It is the website to request the website url and load the website content
Python Script for Website URL Monitoring
Now make a python script app.py
and copy paste the following code
app.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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# Importing libraries import time import hashlib from urllib.request import urlopen, Request # setting the URL you want to monitor url = Request('https://leetcode.com/', 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() print("running") time.sleep(10) while True: try: # 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 time.sleep(30) # 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: continue # if something changed in the hashes else: # notify print("something changed") # again read the website response = urlopen(url).read() # create a hash currentHash = hashlib.sha224(response).hexdigest() # wait for 30 seconds time.sleep(30) continue # To handle exceptions except Exception as e: print("error") |
If you run the app.py
file you will see the following screenshot