我正在尝试弄清楚如何编写网站监控脚本(最后是 cron 作业)以打开给定的 URL,检查标签是否存在,标签是否不存在,或者不包含预期的数据,然后将一些数据写入日志文件,或发送电子邮件。
标签应该是类似或相对类似的东西。
有人有什么想法吗?
最佳答案
你最好的选择是查看BeautifulSoup .像这样:
import urllib2
from BeautifulSoup import BeautifulSoup
page = urllib2.urlopen("http://yoursite.com")
soup = BeautifulSoup(page)
# See the docs on how to search through the soup. I'm not sure what
# you're looking for so my example stops here :)
之后,通过电子邮件发送或记录它是非常标准的费用。
关于用于检查网站标签的 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2610395/