如何同时获取多个提要

gko*_*lan 3 concurrency parsing ruby-on-rails feedparser feedzirra

我是ruby on rails的新手,我刚刚开始观看rails casts教程.

为了解析feed,我已经开始使用feed zirra了.

要一次获取多个Feed,feedzirra具有此功能

feed_urls = ["http://feeds.feedburner.com/PaulDixExplainsNothing",
"http://feeds.feedburner.com/trottercashion"]
feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
Run Code Online (Sandbox Code Playgroud)

如果我有100个Feed,此过程需要一些时间来索引第100个Feed,因此,

如何解析所有这些让我们同时说100个提要?

期待您的帮助和支持

hel*_*inz 6

您可以尝试将Feedzirra用于饲料解析和Typhoeus结合使用以获得可靠性,例如:

#!/usr/bin/env ruby
require 'rubygems'
require 'typhoeus'
require 'feedzirra'

feed_urls = ["http://feeds.feedburner.com/PaulDixExplainsNothing", "http://feeds.feedburner.com/trottercashion"]

hydra = Typhoeus::Hydra.new
feeds = {}

feed_urls.each do |feed|
        r = Typhoeus::Request.new(feed)
        r.on_complete do |response|
                feeds[r.url] = Feedzirra::Feed.parse(response.body)
        end
        hydra.queue r
end
hydra.run
puts feeds.inspect
Run Code Online (Sandbox Code Playgroud)

我们的想法是使用hydra来保持稳定.然后由你做其他事情而不是检查或填充feed变量.