2011-01-20 30 views
2

對於任何類型的提要使用單個解析器的想法非常好,並希望它對我有用。 我一直在試圖讓feedzirra解析atom feed。 明確:Feedzirra無法解析原子提要

  1. http://pindancing.blogspot.com/feeds/posts/default
  2. http://adam.heroku.com/feed

這些只是2,我的問題嘗試是feedzirra無法分析 進入URL。它永遠是

feed = Feedzirra::Feed.fetch_and_parse(search.rss_feed_url) 
p feed.entries.first.title 
p feed.entries.first.url #=> returns nil 

有什麼我需要做的就是它的工作?

感謝您的幫助

回答

3

討厭說「我的作品」,但是,好了,工作對我來說:

require 'Feedzirra' 

urls = %w{ 
    http://adam.heroku.com/feed 
    http://pindancing.blogspot.com/feeds/posts/default 
} 

urls.each do |url| 
    feed = Feedzirra::Feed.fetch_and_parse(url) 
    puts feed.entries.first.title 
    puts feed.entries.first.url 
end 

# => Memcached, a Database? 
# => http://adam.heroku.com/past/2010/7/19/memcached_a_database/ 
# => The answer to "Will you mentor me?" is 
# => http://pindancing.blogspot.com/2010/12/answer-to-will-you-mentor-me-is.html 

它會幫助你看到代碼的其餘部分,特別是您在fetch_and_parse方法中使用的實際參數。

+0

謝謝邁克爾,我使用'feedzirra'(這是pauldix-feedzirra(0.0.18)寶石)。我在我的機器上試過你的代碼,它不起作用。可能是我需要更新寶石?我的紅寶石版本是1.8.7 – truthSeekr

+0

最新版本的Feedzirra是0.0.24。這就是我正在使用的。我已經嘗試了Ruby 1.8.7-p302和Ruby 1.9.2-p136,並且上面的代碼都可以正常工作。 – michaelmichael

+0

邁克爾,feedzirra版本可能是問題。我嘗試更新它,但現在卡住了activesupport依賴關係'activate':無法爲[「feedzirra-0.0.24」]激活activesupport(> = 2.3.8,運行時),已激活activesupport-2.3.5 for [ activerecord-2.3.5「](Gem :: LoadError)'如果你知道一個解決方案讓我知道。我也會環顧四周,找出如何避免依賴。謝謝 – truthSeekr