views:

4741

answers:

5

I'm looking for something that will let me parse Atom and RSS in Ruby and Rails. I've looked at the standard RSS library, but is there one library that will auto-detect whatever type of feed it is and parse it for me?

+7  A: 

Googleage reveals some things. Were they not acceptable?

Simple RSS
Ruby-Feedparser

require 'simple-rss'
require 'open-uri'
rss = SimpleRSS.parse open('http://slashdot.org/index.rdf')
rss.channel.title # => "Slashdot"
Pistos
Simple-RSS looked good, but it hasn't been updated in 2 years. Feedparser also looked pretty good but it appears there's no gem and it's an 0.6. I was hoping there'd be something a bit more mature that's generally the standard.
aronchick
I know how you feel about wanting to use active projects, but if the RSS and RDF specs haven't changed much lately, perhaps these would do the trick. :)
Pistos
i'll give it a shot with Simple RSS - but it really surprises me that there's not a better solution out there - given how web 2.0-y Ruby/Rails and RSS are you'd think there'd be a nice package combining them.
aronchick
It's quite possible there is a rails-specific solution. I haven't googled for it, though.
Pistos
+6  A: 

If you meet crappy feeds, you may want to use HPricot to parse the feed.

Thibaut Barrère
Hpricot = good times. Thanks!
aronchick
Did you settle on Hpricot, I tried this and had a could not get all the information out of a feed. It did fair better than Nokogiri which could not handle malformed feeds.
Kris
Well one time or two, Hpricot could not handle some very broken feed but apart from that all the time it's working fine for me.I'm using it for http://www.learnivore.com for instance.
Thibaut Barrère
+2  A: 

Feed Normalizer looks like it may be a good option

http://rubyforge.org/projects/feed-normalizer/

RichH
it looks like feed-normalizer wraps Simple RSS, from installing it. I just used it to trawl through an OPML file of mixed Rss/Atom feeds - it seemed to be very nicely agnostic, I didn't know or care what it was looking at, which suits me!
Mike Woodhouse
+6  A: 

Feedzirra is one of the better options: http://www.pauldix.net/2009/02/feedzirra-a-ruby-feed-library-built-for-speed.html

Of course, I'm biased since I wrote it. :)

Paul Dix
I agree. Feedzirra is the best. Really fast. Thanks Paul Dix for this amazing library.
Shripad K
Unfortunately, as it is, its active support dependency is broken on its latest version (on rails 2.3.8, not 3). Since I'm not using jruby, and this lib uses native extensions, no osgi for me. Too bad, Feedzirra looked promising....
Daniel Ribeiro
A: 

I like using niokrigi or scrapi for parsing the xml in the atom/rss feeds. http://www.rubyinside.com/nokogiri-ruby-html-parser-and-xml-parser-1288.html

CodeJoust