用于通知任何网页更改的包
webnotifier的Python项目详细描述
网络通知程序
webnotifier是一个简单的包,用于通知任何网页更改。
要求
此套餐需要:
- 请求>;=2.21.0
- lxml=4.3.3
安装
要安装webnotifier,请使用pip
$ pip install webnotifier
用法
实例化WebNotifier类并传递一个URL数组和两个回调。此外,还可以传递间隔时间(以秒为单位)。
fromwebnotifierimportWebNotifiermy_urls=[{'name':'Google','href':'https://www.google.com'},{'name':'Medium','href':'https://medium.com'},{'name':'Localhost','href':'http://127.0.0.1:3000'}]defonError(err):""" URL and Name params can be accessed within err.name && err.url """print("There was an error with {} on {}".format(err.name,err.url))defonNewChange(url,name):print("Webpage {} on {} changed!".format(name,url))interval=60#Check if webpage changes every 60 secondscustom_webnotifier=WebNotifier(my_urls,onNewChange,onError,interval)custom_webnotifier.start()
当网页更改时,将触发onnewchange回调。否则,如果在获取url时有任何错误,将执行onerror回调。