【问题标题】:How do I check if a specific element on a website is changed?如何检查网站上的特定元素是否已更改?
【发布时间】:2022-02-08 04:54:18
【问题描述】:

我目前正在努力争取一个 Zoom 课程的名额,如果我没有名额,我欠驾驶学校 300 美元。长篇大论,但不是很重要。如果缩放注册链接数据已更新,我正在尝试获取通知。我最初试图查看网站的哈希是否在任何时候更新,但我注意到肯定有一些内部时钟发生了变化,让它每分钟通知我一次。我要查看是否将其删除的特定元素是...

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

我不确定如何在哈希中隔离它。以下是我用于检查任何更新的代码。

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")

【问题讨论】:

    标签: python html hash


    【解决方案1】:

    您可以使用Beautiful Soup 来解析创建树状结构的HTML 响应。从您的示例看来,您想要注册 div 的 search for the class。如果未找到任何元素,find method 将返回 None,因此您可以只测试它而不是更改哈希值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 2019-09-27
      • 2012-03-13
      相关资源
      最近更新 更多