代码之家  ›  专栏  ›  技术社区  ›  muhuk

如何检测RSS提要中更改的项目和新项目?

  •  7
  • muhuk  · 技术社区  · 17 年前

    feedparser 或者一些其他Python库来下载和解析RSS提要;我怎样才能可靠地检测到 new modified 项目?

    到目前为止,我在提要中看到了发布日期早于最新项目的新项目。此外,我还看到提要阅读器将内容略有不同的同一项目显示为单独的项目。我没有实现提要阅读器应用程序,我只是想要一个健全的提要数据归档策略。

    2 回复  |  直到 12 年前
        1
  •  6
  •   lt_kije    17 年前

    这取决于你对饲料来源的信任程度。feedparser为提要项提供了一个.id属性——该属性对于RSS和ATOM源都应该是唯一的。例如,参见feedparser的 ATOM docs

        2
  •  1
  •   Emma    5 年前

    有两个 HTTP Features documentation 对于可以完成此操作的feedparser:

    基本概念是,提要发布者在发布提要时可以提供一个特殊的HTTP标头,称为ETag。您应该在后续请求中将此ETag发送回服务器。如果自上次请求以来提要没有更改,服务器将返回一个特殊的HTTP状态代码(304),并且没有提要数据。

        import feedparser
        d = feedparser.parse('` <http://feedparser.org/docs/examples/atom10.xml>`_')
        d.etag``'"6c132-941-ad7e3080"'``
        d2 = feedparser.parse('` <http://feedparser.org/docs/examples/atom10.xml>`_', etag=d.etag)
        d2.status``304``
        d2.feed``{}``
        d2.entries``[]``
        d2.debug_message``'The feed has not changed since you last checked, so
        the server sent no data.  This is a feature, not a bug!'
    

    在这种情况下,服务器在HTTP标头中发布提要的最后修改日期。您可以在后续请求中将其发送回服务器,如果提要没有更改,服务器将返回HTTP状态代码304,并且没有提要数据。

    import feedparser
    d = feedparser.parse('` <http://feedparser.org/docs/examples/atom10.xml>`_')
    d.modified``(2004, 6, 11, 23, 0, 34, 4, 163, 0)``
    d2 = feedparser.parse('` <http://feedparser.org/docs/examples/atom10.xml>`_', modified=d.modified)
    d2.status``304``
    d2.feed``{}``
    d2.entries``[]``
    d2.debug_message``'The feed has not changed since you last checked, so
    the server sent no data.  This is a feature, not a bug!'