什么是实时或几乎获取RSS的最佳方式

时间:2009-10-12 19:12:24

标签: rss real-time feeds bandwidth

我想知道什么是实时获取RSS源的最佳方式,而不必下载整个源,即使它没有被更改。 我并不介意这种语言,我只是在寻找最好的方法。

1 个答案:

答案 0 :(得分:2)

您可以使用ETagIf-Modified-Since标头HTTP标头参数。

以下是一个示例python代码:

etag = ... # etag of previous request
last_modifier = ... # time of last request

req = urllib2.Request(url)
if etag:
    req.add_header("If-None-Match", etag)

if last_modified:
    req.add_header("If-Modified-Since", last_modified)

opener = urllib2.build_opener(NotModifiedHandler())
url_handle = opener.open(req)
headers = url_handle.info()

if hasattr(url_handle, 'code') and url_handle.code == 304:
    # no change happened
else:
    # RSS Feed has changed

代码可以转移到您只需添加必要标头标签的任何语言,并检查返回的代码。

更新:查看此博客文章:HTTP Conditional GET for RSS Hackers

相关问题