215
C H A P T E R 1 1
Using FeedTools to Parse RSS
Google News provides its data in RSS form, which is an XML format, so you could parse
it using a Ruby library like the standard REXML or the XmlSimple or Remarkably gems
(both introduced in Chapter 9). However, FeedTools gives you the advantage of a powerful
interface specific to news feeds, which makes your life much easier.
For example, here??™s how easy it is to print out the titles from the RubyForge news
feed, which lists all the new software released on RubyForge:
require 'feed_tools'
newsfeed=FeedTools::Feed.open('http://rubyforge.org/export/rss_sfnews.php')
newsfeed.items.each do |item|
puts item.title
end
This code results in the following output:
Net::NNTP Client Library:SCM is now Subversion
rb-appscript 0.5.0 released
Open Ruby on Rails Book:openrorbook Download Issues
Duration 0.1.0 released
votigoto 0.2.1 Released
Sequel 0.4.4.2 Released
The second line creates a new FeedTools:Feed object using the open method. The URL
specified is http://rubyforge.
Pages:
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309