python - 尝试将 Discord 警报/挂钩添加到现有的 python 代码
问题描述
所以我想监控一个网页,如果发生变化,我想通过 Discord 收到通知。
搜索谷歌,我登陆了这个页面https://www.adventuresintechland.com/detect-when-a-webpage-changes-with-python/
当我在我的网站上测试它时它似乎工作。但我想在这段代码中添加不和谐警报,但似乎卡住了
我在 github 上查看了 Dhooks 并一直试图实现它
# Hunter Thornsberry
# http://www.adventuresintechland.com
# WebChange.py
# Alerts you when a webpage has changed it's content by comparing checksums of the html.
import hashlib
import urllib2
import random
import time
# url to be scraped
url = "http://raw.adventuresintechland.com/freedom.html"
# time between checks in seconds
sleeptime = 60
def getHash():
# random integer to select user agent
randomint = random.randint(0,7)
# User_Agents
# This helps skirt a bit around servers that detect repeaded requests from the same machine.
# This will not prevent your IP from getting banned but will help a bit by pretending to be different browsers
# and operating systems.
user_agents = [
'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11',
'Opera/9.25 (Windows NT 5.1; U; en)',
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
'Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Kubuntu)',
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0.1) Gecko/20100101 Firefox/8.0.1',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.151 Safari/535.19'
]
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', user_agents[randomint])]
response = opener.open(url)
the_page = response.read()
return hashlib.sha224(the_page).hexdigest()
current_hash = getHash() # Get the current hash, which is what the website is now
while 1: # Run forever
if getHash() == current_hash: # If nothing has changed
print "Not Changed"
else: # If something has changed
print "Changed"
break
time.sleep(sleeptime)
解决方案
推荐阅读
- biztalk - 无法加载文件或程序集
- c# - CRM 插件跟踪日志 - 仅用于沙盒模式的日志
- excel - 如何从 XLS 文件的所有文本框中清除文本,而不删除这些框?
- scroll - 禁用代码镜像元素上的滚动
- python-3.x - 为什么下面的代码没有带来结果?我希望看到一个包含:书名,书价的表格
- corda - Corda - 在合约 jar 上启用签名会导致 deployNodes 任务失败
- url - URL 仅使用 TOR 浏览器解析,否则错误 ERR_NAME_NOT_RESOLVED
- javascript - 如何在测试运行时访问 Nightwatch 中的窗口对象?
- angular - 如何使用 Mocha 和 Karma 配置 Angular 6 项目?
- excel - vba application.workbooks.open() 错误 1004 应用程序定义或对象定义错误