Eli Murphy
Eli Murphy

Reputation: 66

How do I check if a specific element on a website is changed?

I am currently trying to get a spot in a zoom class, and if I don't get a spot I owe a driving school 300 dollars. Long story there, but not very important. I am trying to get a notification if the zoom registration link data has been updated. I originally tried to just see if the hash of the site was updated at any point, but I noticed there must be some internal clock that is changed, making it notify me every minute. The specific element I am looking to see if it is removed is...

<div class="form-group registration-over">Registration is closed.</div>

I am not sure how to isolate it within the hash. Below is the code I have for checking for any update.

import time
import hashlib
from urllib.request import urlopen, Request
import webbrowser
 
url = Request('URL HERE',
              headers={'User-Agent': 'Mozilla/5.0'})

response = urlopen(url).read()
 
currentHash = hashlib.sha224(response).hexdigest()
print("running")
time.sleep(10)
while True:
    try:
        response = urlopen(url).read()
         
        currentHash = hashlib.sha224(response).hexdigest()
         
        time.sleep(30)
         
        response = urlopen(url).read()
         
        newHash = hashlib.sha224(response).hexdigest()
 
        if newHash == currentHash:
            continue
 
        else:
            from datetime import datetime
            now = datetime.now()
            nowtime = now.strftime("%H:%M:%S: ")
            print(nowtime, "Something changed")
            webbrowser.open('URL HERE')
 
            response = urlopen(url).read()
 
            currentHash = hashlib.sha224(response).hexdigest()
 
            time.sleep(30)
            continue
             
    except Exception as e:
        print("error")

Upvotes: 1

Views: 1124

Answers (1)

O.Schmitt
O.Schmitt

Reputation: 129

You can use Beautiful Soup to parse the HTML response which creates a tree-like structure. From your example it looks like you want to search for the class of the registration div. The find method returns None if no element is found, so you could just test for that instead of the hash change.

Upvotes: 2

Related Questions