0
我想使用Ruby的RSS class解析Atom和RSS提要,所以我可以從它們中提取鏈接。如何區分代碼中的兩種類型?使用Ruby的RSS類來解析Atom和RSS
我有一個解析器響應準備就緒如此。
response = RSS::Parser.parse(rss_url, false)
我想使用Ruby的RSS class解析Atom和RSS提要,所以我可以從它們中提取鏈接。如何區分代碼中的兩種類型?使用Ruby的RSS類來解析Atom和RSS
我有一個解析器響應準備就緒如此。
response = RSS::Parser.parse(rss_url, false)
我發現進料對象.feed_type
方法,並用它像這樣:
if response.feed_type == "rss"
puts "hey rss"
response.channel.items.each{ |item| links += "'#{item.link}'," }
elsif response.feed_type == "atom"
puts "hey atom"
response.entries.each{ |entry| links += "'#{entry.link.href}'," }
else
puts "something went wrong"
end