从 JavaScript 中的 RSS 提要获取附件 URL
Get enclosure URL from RSS feed in JavaScript
我试过这个论坛上的其他答案,但没有任何运气。我正在尝试从 RSS 提要中提取每个条目的附件 URL(它包含 mp3 音频的直接 link),因此我可以创建一个包含内置播放器的页面对于所有音频。
这是我目前的情况:
var FEED_URL = 'https://www.spreaker.com/show/1720272/episodes/feed';
$.ajax({
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(FEED_URL),
dataType: 'json',
success: function(data) {
$(data).find("item").each(function(i) {
var URL = $(this).find("enclosure").attr("url");
console.log(URL);
});
}
})
以下是其中一项的示例:
<item>
<title>Episode 2 - 7 Minute Leadership</title>
<link>https://www.spreaker.com/user/paul_falavolito/epsiode-2-7-minute-leadership</link>
<description>Why should anyone be led by you?</description>
<guid isPermaLink="false">https://api.spreaker.com/episode/8296378</guid>
<pubDate>Tue, 19 Apr 2016 13:16:50 +0000</pubDate>
<enclosure url="https://api.spreaker.com/download/episode/8296378/episode_2_7_minute_leadership.mp3" length="0" type="audio/mpeg"></enclosure>
<itunes:author>Paul Falavolito</itunes:author>
<itunes:subtitle>Why should anyone be led by you?</itunes:subtitle>
<itunes:summary>Why should anyone be led by you?</itunes:summary>
<itunes:duration>713</itunes:duration>
<itunes:keywords>motivation,business,leadership</itunes:keywords>
<itunes:explicit>clean</itunes:explicit>
<itunes:image href="https://d3wo5wojvuv7l.cloudfront.net/t_rss_itunes_square_1400/images.spreaker.com/original/f71be8f6c859a4ce5669a83cbf3bcd31.jpg"/>
</item>
您可以看到有一个引用 mp3 的附件 URL。这就是我要提取的 URL。
如有任何建议,我们将不胜感激。
这就是我最终得到外壳的方式 url:
$(document).ready(function() {
var feed = "https://crossorigin.me/https://www.spreaker.com/show/1720272/episodes/feed";
$.ajax(feed, {
accepts: {
xml: "application/rss+xml"
},
dataType: "xml",
success: function(data) {
$(data).find("enclosure").each(function() {
var el = $.parseHTML($(this)[0].outerHTML);
var url = $(el).attr('url');
console.log(url);
});
}
});
});
我试过这个论坛上的其他答案,但没有任何运气。我正在尝试从 RSS 提要中提取每个条目的附件 URL(它包含 mp3 音频的直接 link),因此我可以创建一个包含内置播放器的页面对于所有音频。
这是我目前的情况:
var FEED_URL = 'https://www.spreaker.com/show/1720272/episodes/feed';
$.ajax({
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(FEED_URL),
dataType: 'json',
success: function(data) {
$(data).find("item").each(function(i) {
var URL = $(this).find("enclosure").attr("url");
console.log(URL);
});
}
})
以下是其中一项的示例:
<item>
<title>Episode 2 - 7 Minute Leadership</title>
<link>https://www.spreaker.com/user/paul_falavolito/epsiode-2-7-minute-leadership</link>
<description>Why should anyone be led by you?</description>
<guid isPermaLink="false">https://api.spreaker.com/episode/8296378</guid>
<pubDate>Tue, 19 Apr 2016 13:16:50 +0000</pubDate>
<enclosure url="https://api.spreaker.com/download/episode/8296378/episode_2_7_minute_leadership.mp3" length="0" type="audio/mpeg"></enclosure>
<itunes:author>Paul Falavolito</itunes:author>
<itunes:subtitle>Why should anyone be led by you?</itunes:subtitle>
<itunes:summary>Why should anyone be led by you?</itunes:summary>
<itunes:duration>713</itunes:duration>
<itunes:keywords>motivation,business,leadership</itunes:keywords>
<itunes:explicit>clean</itunes:explicit>
<itunes:image href="https://d3wo5wojvuv7l.cloudfront.net/t_rss_itunes_square_1400/images.spreaker.com/original/f71be8f6c859a4ce5669a83cbf3bcd31.jpg"/>
</item>
您可以看到有一个引用 mp3 的附件 URL。这就是我要提取的 URL。
如有任何建议,我们将不胜感激。
这就是我最终得到外壳的方式 url:
$(document).ready(function() {
var feed = "https://crossorigin.me/https://www.spreaker.com/show/1720272/episodes/feed";
$.ajax(feed, {
accepts: {
xml: "application/rss+xml"
},
dataType: "xml",
success: function(data) {
$(data).find("enclosure").each(function() {
var el = $.parseHTML($(this)[0].outerHTML);
var url = $(el).attr('url');
console.log(url);
});
}
});
});