0

what is the best way to detect whether a given url is actually an RSS feed?

daniel
  • 3
  • 1
  • i just came up with an idea, to check how many title tags are in it.. cause if you got more than 3 its definitely RSS?! – daniel Mar 20 '10 at 20:24

2 Answers2

3

It's tough to do reliably if the URLs you need to check are arbitrary.

One thing would be the content-type it serves. That can change, though, because (IIRC) IE needs text/xml to display an actual feed, and not to offer to download it. For more on the issue see here.

The second (and more reliable) thing would be to analyze the file's structure. Some ideas are here: How to detect if a page is an RSS or ATOM feed

The simplest way could be, as Pascal Martin recommends in that question, opening an URL with the Zend RSS reader. If that works out, it's a valid RSS resource, otherwise, it's not.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

If you are a python developer this is quite easy. I faced the same situation a while ago. First install the libray "feedparser" on your system as a python library

For example your feed link is = "www.example.org/feed" chk the following

    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"
minocha
  • 1,043
  • 1
  • 12
  • 26