Problem extracting text from RSS feeds

Posted by Gautam on Stack Overflow See other posts from Stack Overflow or by Gautam
Published on 2010-05-26T19:04:51Z Indexed on 2010/05/26 23:21 UTC
Read the original article Hit count: 330

Hi, I am new to the world of Ruby and Rails.

I have seen rails cast 190 and I just started playing with it. I used selector gadget to find out the CSS and XPath

I have the following code..

require 'rubygems'  
require 'nokogiri'  
require 'open-uri'  

url = "http://www.telegraph.co.uk/sport/football/rss"  
doc = Nokogiri::HTML(open(url))  
doc.xpath('//a').each do |paragraph|
puts paragraph.text
end

When I extracted text from a normal HTML page with css, I could get the extracted text on the console.

But when I try to do the same either with CSS or XPath for the RSS Feed for the following URL mentioned in the code above, I dont get any output.

How do you extract text from RSS feeds??

I also have another silly question.

Is there a way to extract text from 2 different feeds and display it on the console

something like

url1 = "http://www.telegraph.co.uk/sport/football/rss"
url2 = "http://www.telegraph.co.uk/sport/cricket/rss"

Looking forward for your help and suggestions

Thank You

Gautam

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about nokogiri