【问题标题】:How to fetch multiple feeds concurrently如何同时获取多个提要
【发布时间】:2010-08-31 16:14:05
【问题描述】:

我是 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 个提要?

期待您的帮助和支持

【问题讨论】:

    标签: ruby-on-rails parsing concurrency feedparser feedzirra


    【解决方案1】:

    您可以尝试将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 来实现并发。除了检查或填充 feeds 变量之外,您还可以做其他事情。

    【讨论】:

      猜你喜欢
      • 2021-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 2019-08-19
      • 1970-01-01
      相关资源
      最近更新 更多