Python 如何在不重新加载的情况下检测网页上的更改
我发现可以使用perl进行检测。 但不幸的是,我不懂perl。 python有什么方法吗?Python 如何在不重新加载的情况下检测网页上的更改,python,Python,我发现可以使用perl进行检测。 但不幸的是,我不懂perl。 python有什么方法吗? 如果不复杂化,你能给出一个详细的例子吗?你是说一个python脚本,它读取一个网页并向你显示它是否与上次访问不同?非常简单的版本如下(适用于python2和python3): 如果你有任何问题,请告诉我 #!/usr/bin/env python # -*- coding: utf-8 -*- import sys import os import requests from hashlib impo
如果不复杂化,你能给出一个详细的例子吗?你是说一个python脚本,它读取一个网页并向你显示它是否与上次访问不同?非常简单的版本如下(适用于python2和python3): 如果你有任何问题,请告诉我
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import requests
from hashlib import sha1
recent_hash_filename = ".recent_hash"
def test(url):
print("looking up %s" % url)
if not os.path.exists(recent_hash_filename):
open(recent_hash_filename, 'a').close()
hash_fetched = sha1()
hash_read = ""
r = requests.get(url)
hash_fetched.update(r.text.encode("utf8"))
with open(recent_hash_filename) as f:
hash_read = f.read()
print(hash_fetched.hexdigest())
print(hash_read)
if hash_fetched.hexdigest() == hash_read:
print("same")
else:
print("different")
with open(recent_hash_filename, "w") as f:
f.write(hash_fetched.hexdigest())
if __name__ == '__main__':
if len(sys.argv) > 1:
url = sys.argv[1]
else:
url = "https://www.heise.de"
test(url)
print("done")