Limit an RSS Feed in Ruby -
this seems such simple thing isn't worth question, haven't yet found answer! parsing rss feed using
@rss_industry = rss::parser.parse('http://construction.com/rss/construction.xml', false) this brings entire feed. want limit number of items returned. there simple way this?
thanks.
it doesn't that's feature in stdlib rss::parser class.
there other ways parse rss.
but there's no way avoid fetching entire xml file on http, if you're interested in first x items. , you've fetched it, there's no great way avoid parsing entire xml, if want parts of it. there might some complicated way using streaming xml parser, unless xml file really huge, don't want go down there.
instead, if interested in first x items in feed, why not @ those?
feed = rss::parser.parse('http://construction.com/rss/construction.xml', false) all_items = feed.items first_10_items = feed.items.slice(0, 10)
Comments
Post a Comment