Python:如何使用 feedparser 和 etags 检查 RSS 更新

标签 python rss http-headers etag feedparser

我试图跳过未使用 feedparser 和 etags 修改的 RSS 提要。 遵循文档指南:http://pythonhosted.org/feedparser/http-etag.html

import feedparser

d = feedparser.parse('http://www.wired.com/wiredscience/feed/')
d2 = feedparser.parse('http://www.wired.com/wiredscience/feed/', etag=d.etag)

print d2.status

这个输出:

200

这个脚本不应该返回 304 吗? 我的理解是,当 RSS 提要更新时,etag 会发生变化,如果它们匹配,那么我应该得到 304。

为什么我没有得到预期的结果?

最佳答案

显然,此服务器配置为检查“If-Modified-Since” header 。您还需要传递上次修改时间:

>>> d = feedparser.parse('http://www.wired.com/wiredscience/feed/')
>>> feedparser.parse('http://www.wired.com/wiredscience/feed/', 
                     etag=d.etag, modified=d.modified).status
304
>>> feedparser.parse('http://www.wired.com/wiredscience/feed/', 
                     etag=d.etag).status
200

关于Python:如何使用 feedparser 和 etags 检查 RSS 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16745083/

相关文章:

python - 如何使用 Python Suds(版本 0.3.6)SOAP 库 : TypeNotFound exception? 导入 XSD 模式

rss - 面向Web开发人员的最佳新闻提要,RSS

c# - 如何防止 HttpClient 发送连接 header

http - 对 HTTP 规范中使用的实体的混淆

ruby-on-rails - Apipie 干扰正确的错误代码

python - 列出 Python 文件中使用的所有第三方包及其自身的函数

python - 使用 Python 快速音译阿拉伯文本

python - 创建用于将非字母数字字符转换为破折号的 Python 类

api - Pinterest 板列表

php - 内容聚合服务策略