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}" }
Thank you, this is just the code snippet I need to begin pulling news headlines into an upcoming project.
simple than feedtools
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.
@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:
Links
Archives
Tags
actionmailer activerecord ajax apple capistrano code golf css db delete eager loading ebay email attachment erb flash ftp generators get haml helpers ie sucks javascript jquery lightbox lost merb net ftp paperclip passenger plexus post rails rails machine railsconf redesign rest rjs routes rss ruby safari script text replacement tips tutorial twitter xhtml
Projects
© 2009 Travis Roberts. All rights reserved.
Nick said on June 21, 2007:
Thanks, so very very simple.