监控网页哈希PY代码

import requests
import hashlib
import time
import smtplib
from email.mime.text import MIMEText

url = 'https://'

def get_hash(url):
response = requests.get(url)
return hashlib.sha256(response.content).hexdigest()
# 发送邮件的参数
def send_email(content):
sender = '你的发件人邮箱'
receiver = '你的收件人邮箱'
smtp_server = 'smtp.xxx.com' # 发件人邮箱的 SMTP 服务器地址
smtp_port = 465 # 发件人邮箱的 SMTP 端口
username = '你的发件人邮箱'
password = '你的发件人邮箱密码'

message = MIMEText(content)
message['From'] = sender
message['To'] = receiver
message['Subject'] = 'Website Change Alert'

server = smtplib.SMTP_SSL(smtp_server, smtp_port)
server.login(sender, password)
server.sendmail(sender, receiver, message.as_string())
server.quit()

current_hash = get_hash(url)
while True:
new_hash = get_hash(url)
if new_hash != current_hash:
send_email('Website content has changed.')
current_hash = new_hash
else:
time.sleep(30)
nohup python3 jiankong.py > output.log 2>&1 &

正文完
 0
admin
版权声明:本文于2023-03-27转载自iweec,共计810字。
转载提示:此文章非本站原创文章,若需转载请联系原作者获得转载授权。