Catching website changes with python using urlopen read function

31 views Asked by At

Hi I am a high school student who has not used python to code programs much, and I was having trouble with creating code to check when a website was updated. I have looked at different resources and I have used them to create what I have but when I run the code it doesn't seem to work and do what I expect it to do. When I run the code I expect it to tell me if a site has been updated or stayed the same from when I last checked it. I put some print statements in the code to try to catch the issue, but it has only showed me that the website has changed even though it doesn't look like it has changed.

import time
import hashlib
from urllib.request import urlopen, Request

url = Request('https://www.canada.ca/en/immigration-refugees-citizenship/services/immigrate-canada/express-entry/submit-profile/rounds-invitations.html')
res = urlopen(url).read()
current = hashlib.sha224(res).hexdigest()
print("running")
time.sleep(10) 
while True:
    try:
        res = urlopen(url).read()
        current = hashlib.sha224(res).hexdigest()
        print(current)
        print(res)
        time.sleep(30)
        res = urlopen(url).read()
        newHash = hashlib.sha224(res).hexdigest()
        print (newHash)
        print(res)
        if newHash == current:
            print ("nothing changed")
            continue
        else:
            print("there was a change")
    except AttributeError as e:
        print ("error")
0

There are 0 answers