3

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

为了解析提要,我已经开始使用提要 zirra。

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

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

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

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

期待您的帮助和支持

4

1 回答 1

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

这个想法是使用 hydra 来实现并发。然后由您来做除了检查或填充 feed 变量之外的其他事情。

于 2010-08-31T16:36:41.757 回答