用JavaScript从RSS提要获取附件URL
Get enclosure URL from RSS feed in JavaScript
我试过这个论坛上的其他答案,但没有任何运气。我试图从RSS提要中提取每个条目的附件URL(它包含mp3音频的直接链接),因此我可以创建一个包含所有音频内置播放器的页面。
到目前为止我写的是:
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>
你可以看到有一个附件URL指向一个mp3。这就是我要提取的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);
});
}
});
});
相关文章:
- Firebase-登录时获取url
- 正在捕获.单击以获取URL
- Javascript获取url并通过添加到其中进行重定向
- 如何使用javascript从同一浏览器下的其他页面获取URL?有可能吗
- 如何从Beautiful Soup获取URL
- 我想从iframe获取url
- 使用Javascript获取URL参数
- 在 Javascript 中获取 URL-Parameter 不适用于 urlencode'&'
- 如何创建一个组件,我可以设置在 Angular 2 中的属性中获取 URL 数据
- 如何使用jQuery获取url的最后两个字符
- 使用jquery获取url参数
- 如何获取url中参数的真实值
- 使用表单和POST方法通过Javascript获取URL参数
- nodejs:在OutgoingMessage中获取url
- PHP-忽略换行符获取url
- 如何在Javascript中获取url的hashtag值和amp值
- 获取URL附加的复选框值
- 如何使用Javascript获取URL参数
- 如何使用Javascript获取URL参数
- 从2组单选按钮中获取url