gpt4 book ai didi

ruby 、Feedzirra、斑疹伤寒

转载 作者:太空宇宙 更新时间:2023-11-03 16:09:48 24 4
gpt4 key购买 nike

我真的是 Ruby 的新手(第一天!),我正在努力解决这个问题。我正在尝试结合 Typhoeus 构建一个 rss-parser,因为我正在解析 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="....

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

最佳答案

您似乎在 on_complete block 内排队。您不应该在 feed_urls.each block 中排队吗?或者,也许您应该在完成所有请求后检查所有条目?像这样:

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

关于 ruby 、Feedzirra、斑疹伤寒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6312911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com