首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >红宝石,Feedzirra,typhoeus

红宝石,Feedzirra,typhoeus
EN

Stack Overflow用户
提问于 2011-06-11 07:07:49
回答 2查看 793关注 0票数 2

我是Ruby的新手(第一天!)我正在努力解决这个问题。我正在尝试构建一个rss解析器与Typhoeus相结合,因为我要解析超过100个提要,也因为我想让它正常工作。

这就是我的代码:

代码语言:javascript
复制
require 'typhoeus'
require 'feedzirra'

feed_urls = ["feed1", "feed2"]

hydra = Typhoeus::Hydra.new
feeds = {}
entry = {}
feed_urls.each do |feed|
  r = Typhoeus::Request.new(feed)
  r.on_complete do |response|
    feeds[r.url] = response.body
    feeds[r.url] = Feedzirra::Feed.parse(response.body)
    entry = feeds.entries.each do |entry|
      puts entry.title
    end
    hydra.queue r
  end
end

hydra.run

我敢肯定这是一些语法问题。我仍然有一些困难的时候。例如,我总是使用;结束行,尽管我在编写PHP时总是忘记它。所以,也许有人能帮上忙?在没有台风的情况下获得反馈结果并不是太难。

编辑:

代码语言:javascript
复制
>> puts feeds.entries.inspect
[["http://feedurl", #<Feedzirra::Parser::AtomFeedBurner:0x1023b53f0 @title="Paul Dix Explains Nothing", @entries=[#<Feedzirra::Parser::AtomFeedBurnerEntry:0x1023b05d0 @published=Thu Jan 13 16:59:00 UTC 2011, @author="Paul Dix", @summary="Earlier this week I had the opportunity to sit with six other people from the NYC technology scene and talk to NYC Council Speaker Christine Quinn and a few members of her staff. Charlie O'Donnell organized the event to help...", @updated=Thu Jan 13 17:55:31 UTC 2011, @title="Water water everywhere and not a drop to drink: The Myth and Truth of the NYC engineer shortage", @entry_id="tag:typepad.com,2003:post-6a00d8341f4a0d53ef0148c793f692970c", @content="....

所以,我至少得到了一些东西。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-11 07:54:57

您似乎是在on_complete块中退出。您不应该在feed_urls.each块中排队吗?或者,也许你应该在所有的请求都完成之后再检查所有的条目?如下所示:

代码语言:javascript
复制
hydra = Typhoeus::Hydra.new
feeds = {}
entry = {}
feed_urls = ["feed1", "feed2"]

feed_urls.each do |feed|
  r = Typhoeus::Request.new(feed)
  r.on_complete do |response|
      feeds[r.url] = response.body
      feeds[r.url] = Feedzirra::Feed.parse(response.body)
  end

  hydra.queue r
end

hydra.run

feeds.entries.each do |feed|
  puts "-- " + feed[1].title

  feed[1].entries.each do |entry|
    puts entry.title
  end
end
票数 2
EN

Stack Overflow用户

发布于 2011-06-11 07:24:20

你的街区尽头少了一个end。如果您一致地缩进您的代码,您将看到漏洞:

代码语言:javascript
复制
require 'typhoeus'
require 'feedzirra'
feed_urls = ["feed1", "feed2"]    
hydra = Typhoeus::Hydra.new
feeds = {}
entry = {}
feed_urls.each do |feed|
  r = Typhoeus::Request.new(feed)
  r.on_complete do |response|
    feeds[r.url] = response.body
    feeds[r.url] = Feedzirra::Feed.parse(response.body)
    entry = feeds.entries.each do |entry|
      puts entry.title
    end
    hydra.queue r
  end

### You need an 'end' on this line to close the `each` ###

hydra.run

欢迎使用Ruby和Stack Overflow!:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6312911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档