检查网页内容是否已更改(OSM-tile,python)

Check web content changed (OSM-tile, python)

在我的 Python 代码中,我从 Openstreetmap (OSM) 下载图块。出于性能和流量原因,它们存储在临时存储中。然而,在重新使用这些数据之前,我想检查一下这些数据是否仍然是最新的。

这是简单的下载方式:

import urllib2

# Normal import without Version control:
url = r"http://a.tile.openstreetmap.org/1/1/1.png"
imgstr = urllib2.urlopen(url).read()

我正在搜索类似这样的东西(伪代码)

imgstr = ...        # Value from database
local_version = ... # Value from database
online_version = getolineversionnumber(url)
if not(online_version==local_verion):
    imgstr = urllib2.urlopen(url).read()
    version = online_version

getolineversionnumber这样的功能吗?

**问题由 scai 提示回答。不需要更多的答案。 **

post 为其他读者回答自己的问题是一种很好的做法。这是我学到的。

我正在搜索的 属性 称为 etag (https://en.wikipedia.org/wiki/HTTP_ETag)。 并像这样访问:

import urllib2
url = r"http://a.tile.openstreetmap.org/1/1/1.png"
request = urllib2.Request(url)
opener = urllib2.build_opener()
firstdatastream = opener.open(request)
online_version=firstdatastream.headers.dict['etag']