Parsing an RSS feed with Ruby

JUN

09

2007

Parsing an RSS feed is insanely simple with Ruby. Two lines is all it takes. . .

            require 'rss'
            rss = RSS::Parser.parse(open('http://www.travisonrails.com/feed/posts').read, false)
            

Now you'll have an Array of the results, so you can do something like:

            rss.items.each { |i| puts "#{i.title} - #{i.date}" }
            

Tagged: ruby, rss, tutorial


Nick said on June 21, 2007:

Thanks, so very very simple.

Trevor said on October 16, 2007:

Thank you, this is just the code snippet I need to begin pulling news headlines into an upcoming project.

neokain said on September 19, 2008:

simple than feedtools

doug said on January 23, 2009:

This does nothing for caching the rss content though. If you embed this on say your home page then you'll be hitting the rss feed on every page load. Not very kind to the poor rss feed. I think that's the point of feedtools: to integrate http caching with RSS parsing.

Travis said on January 26, 2009:

@doug I agree that you shouldn't use this on every pageload. I use it in a nightly rake task that collects feeds.

Leave a comment:



Projects

Listode

© 2009 Travis Roberts. All rights reserved.