【问题标题】:recognize detect RSS feed using PHP识别使用 PHP 检测 RSS 提要
【发布时间】:2010-03-20 20:17:13
【问题描述】:

检测给定网址是否实际上是 RSS 提要的最佳方法是什么?

【问题讨论】:

  • 我刚刚想出了一个主意,检查其中有多少个标题标签。因为如果你有超过 3 个它肯定是 RSS?!

标签: php rss


【解决方案1】:

如果您需要检查的 URL 是任意的,则很难做到可靠。

一件事就是它所服务的content-type。但是,这可能会改变,因为(IIRC)IE 需要text/xml 来显示实际的提要,而不是提供下载它。有关该问题的更多信息,请参阅here

第二件事(也是更可靠的)是分析文件的结构。一些想法在这里:How to detect if a page is an RSS or ATOM feed

正如 Pascal Martin 在该问题中建议的那样,最简单的方法是使用 Zend RSS 阅读器打开一个 URL。如果成功,它就是一个有效的 RSS 资源,否则,它不是。

【讨论】:

    【解决方案2】:

    如果您是 python 开发人员,这很容易。不久前我也遇到过同样的情况。 首先在您的系统上安装 libray “feedparser” 作为 python 库

    例如,您的提要链接是 = "www.example.org/feed" 检查以下内容

        import feedparser
        f=feedparser.parse("www.example.org/feed")
        if len(f.version)>0:
            print "It is a feed with version",str(f.version)   #Since the parsing is done and versions are allocated only to actual valid feeds otherwise an empty string is there 
        else:
            print "Not a Valid Feed Url"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-18
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 2010-11-22
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      相关资源
      最近更新 更多