我正在使用Feedjira的fetch_and_parse方法来解析我的应用中的RSS提要,但我提供的一些RSS提要是重定向到另一个提要网址的提要网址,而Feedjira并未遵循这些重定向和我的fetch_and_parse失败了。有没有办法让Feedjira遵循RSS重定向?
答案 0 :(得分:1)
我遇到了同样的问题,并通过手动获取Feed(使用Faraday)并使用生成的XML调用FeedJira::Feed.parse
来解决它:
def fetch(host, url)
conn = Faraday.new(:url => host) do |faraday|
faraday.use FaradayMiddleware::FollowRedirects, limit: 3
end
response = conn.get url
return response.body
end
xml = fetch("http://www.npr.org", "/templates/rss/podcast.php?id=510298")
podcast = Feedjira::Feed.parse(xml)
你也可以修补Feedjira的connection
方法做同样的事情,虽然我不推荐它:
module Feedjira
class Feed
def self.connection(url)
Faraday.new(url: url) do |conn|
conn.use FaradayMiddleware::FollowRedirects, limit: 3
end
end
end
end
podcast = Feedjira::Feed.fetch_and_parse("http://www.npr.org/templates/rss/podcast.php?id=510298")