Parsing an RSS feed with Ruby

Published on June 9, 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


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.

Leave a comment:




©2008 Travis Roberts. All rights reserved.