RSS standard lib?

Hi, all…

I used to use “feedtools” (now defunct) and I am trying to switch over
to the RSS stdlib.

Can anyone tell me why this doesn’t work? (Error below)

Thanks,
Hal

require ‘rss’
require ‘open-uri’

URL = “http://feeds.space.com/SpacecomUniversalSpacePodcast

rss = open(URL).read
feed = RSS::Parser.parse(rss)
puts “Description: #{feed.title}”
feed.items.each.with_index {|item,i| puts “#{i+1}. #{item.title}” }

Error is:

/Users/Hal/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rss/2.0.rb:53:in
rescue in pubDate=': value <Thu, 05 July 2007 4:00:00 GMT> of tag <pubDate> is not available. (RSS::NotAvailableValueError) from /Users/Hal/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rss/2.0.rb:50:inpubDate=’
from
/Users/Hal/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rss/parser.rb:456:in
block in start_get_text_element' from /Users/Hal/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rss/parser.rb:358:incall’
from
/Users/Hal/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rss/parser.rb:358:in
tag_end' from /Users/Hal/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rexml/parsers/streamparser.rb:26:inparse’
from
/Users/Hal/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rexml/document.rb:243:in
parse_stream' from /Users/Hal/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rss/rexmlparser.rb:22:in_parse’
from
/Users/Hal/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rss/parser.rb:164:in
parse' from /Users/Hal/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rss/parser.rb:79:inparse’

Hi,

In [email protected]
“RSS standard lib?” on Wed, 20 Mar 2013 06:47:35 +0900,
Hal F. [email protected] wrote:

I used to use “feedtools” (now defunct) and I am trying to switch over
to the RSS stdlib.

Can anyone tell me why this doesn’t work? (Error below)

require ‘rss’
require ‘open-uri’

URL = “http://feeds.space.com/SpacecomUniversalSpacePodcast

rss = open(URL).read
feed = RSS::Parser.parse(rss)
puts “Description: #{feed.title}”
feed.items.each.with_index {|item,i| puts “#{i+1}. #{item.title}” }

Try the following:

require ‘rss’
require ‘open-uri’

URL = “http://feeds.space.com/SpacecomUniversalSpacePodcast

rss = open(URL).read
feed = RSS::Parser.parse(rss, false)
puts “Description: #{feed.channel.title}”
feed.items.each.with_index {|item,i| puts “#{i+1}. #{item.title}” }

Points:

  • Add false argument to RSS::Parser.parse as the second argument.
    It means “the parser doesn’t validate value”.
  • Change “feed.title” to “feed.channel.title”.
    /rss/channel/title is the title of the feed in RSS 2.0.

Thanks,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs