红宝石、Feedzirra、伤寒
我对 Ruby 真的很陌生(第一天!),我在这里遇到了困难。我正在尝试与 Typhoeus 结合构建一个 rss 解析器,因为我正在解析 100 多个提要,也因为我想让它正常工作。
这就是我的代码:
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 时我总是忘记它。那么,也许有人可以帮忙?在没有伤寒的情况下获得饲料结果并不难。
编辑:
>> 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="....
所以,我至少得到了一些东西。
I'm really new to Ruby (first day!) and I'm struggling with this here. I'm trying to build a rss-parser in combination with Typhoeus since I'm parsing over 100 feeds and also because I want to get it working.
So that is my code here:
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
I'm sure it's some syntax problem. I still have some hard times. For example I always keep closing lines with ;
although I forget it all the time when writing PHP. So, maybe someone could help? Getting feed-results without typhoeus wasn't too hard.
edit:
>> 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="....
So, I at least get something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您正在 on_complete 块内排队。你不应该在 feed_urls.each 块中排队吗?或者也许您应该在所有请求完成后检查所有条目?像这样:
It seems that you are queing inside the on_complete block. Shouldn't you queue in the feed_urls.each block? Or maybe you should go through all the entries after all requests have been completed? Like this:
您在块的末尾缺少
end
。如果你一致地缩进你的代码,你会看到这个漏洞:欢迎使用 Ruby 和 Stack Overflow! :)
You're missing an
end
at the end of your block. If you indent your code consistently, you will see the hole:Welcome to Ruby and Stack Overflow! :)