How to check if content of webpage has been changed?

前端 未结 6 1098
失恋的感觉
失恋的感觉 2020-12-30 11:23

Basically I\'m trying to run some code (Python 2.7) if the content on a website changes, otherwise wait for a bit and check it later.

I\'m thinking of comparing

6条回答
  •  无人及你
    2020-12-30 11:52

    You should do an HTTP HEAD request (so you don't download the file) and look at the "Last-modified" header in the response.

    import requests
    
    response = requests.head(url)
    datetime_str = response.headers["last-modified"]
    

    And keep checking if that field changes in a while loop and compare the datetime difference.

    I did a little program on Python to do that:

    https://github.com/javierdechile/check_updates_http

提交回复
热议问题