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

发布于 2024-08-08 09:23:46 字数 70 浏览 1 评论 0原文

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

I would like to know what's the best way to fetch RSS feeds in real time without having to download the entire feed even when it hasn't been changed.
I don't really mind the language, I'm just looking for the best way to do that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-08-15 09:23:46

您可以使用 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

该代码可以转换为任何语言,只需添加必要的标头标签并检查返回的代码即可。

更新:查看此博客文章:针对 RSS 黑客的 HTTP 条件 GET

You can use ETag and If-Modified-Since header HTTP header parameters.

Here is a sample python code:

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

The code can be transferred to any language where you just add the necessary header tags and check the returned code.

UPDATE: Checkout this blog entry: HTTP Conditional GET for RSS Hackers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文