Get date from RSS feed in Ruby

I follow the instructions at http://www.rubyrss.com/ to analyze the feed from craigslist.org:

http://seattle.craigslist.org/sof/index.rss

Everything seems to be working fine, but when I cannot get any dates from the parsed object:

irb(main):010:0> rss.date
NoMethodError: undefined method `date' for #<RSS::RDF:0x2c412b8>
        from (irb):10
irb(main):011:0> rss.channel.date
NoMethodError: undefined method `date' for #<RSS::RDF::Channel:0x2c406ec>
        from (irb):11
        from :0
irb(main):012:0> rss.items[0].date
NoMethodError: undefined method `date' for #<RSS::RDF::Item:0x2cdc290>
        from (irb):12
        from :0
irb(main):013:0> rss.items[1].date
NoMethodError: undefined method `date' for #<RSS::RDF::Item:0x2cd04a4>
        from (irb):13
        from :0

What am I doing wrong here?

+3
source share
2 answers

Take a look at the RSS feed using Firefox so you can easily see the feed structure. Date items are represented using the Dublin Core<dc:date>

Try the following:

require 'rss/dublincore'
rss.items[3].dc_date  #=>  Sat Apr 18 01:02:11 -0400 2009

Details link to Ruby rss parser and Dublin Core .

+2
source

. Feedzirra. , , , .

require "feedzirra"
feed = Feedzirra::Feed.fetch_and_parse("http://seattle.craigslist.org/sof/index.rss")
feed.entries.first.published
# => Fri Apr 24 18:27:28 UTC 2009
+4

Source: https://habr.com/ru/post/1706641/


All Articles