DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Read And Parse RSS Feed

09.09.2005
| 3898 views |
  • submit to reddit
        
require 'open-uri'

require 'rss/0.9'
require 'rss/1.0'
require 'rss/2.0'
require 'rss/parser'

url = 'http://some.host/rss.xml'
rss = RSS::Parser.parse(open(url){|fd|fd.read})
puts rss.items.collect{|item|item.title}.join("\n")

See also <a href='http://simple-rss.rubyforge.org/'>simple-rss</a> at rubyforge.    

Comments

Danny Lagrouw replied on Mon, 2006/01/09 - 6:40am

This code crashed on most feeds I tried to read with it. SimpleRss works very well though!