通过 yahooapis 获取 RSS 订阅内容

简爱代码>JavaScript2015-5-15 19:1343000

通过 强大的  获取 其他网站的 RSS 订阅内容

主要代码是 JS 与一个 API 接口,速度还一般,稳定性 应该没问题,就怕 屏(都懂得)蔽

接口示例

http://query.yahooapis.com/v1/public/yql?format=json&q=select * from rss where url="http://www.gouji.org/rss.php"

其中http://www.gouji.org/rss.php 就是你要获取的 RSS 地址

接口支持跨域, 如果不行可用 JSONP 方法调用


具体实现的例子如下:

<!doctype html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<title>通过 yahooapis 获取 RSS DEMO</title>
	<link rel="stylesheet" href="http://api.asilu.com/cdn/?dialog/dialog.css">
	<script src="http://api.asilu.com/cdn/?jquery.min.js,dialog.min.js,md5.js"></script>
	<style>.demo_rss_div {display: none;width: 300px;}.demo_rss_li:hover .demo_rss_div {display: block}</style>
</head>
<body>

<h1>通过 yahooapis 获取 RSS DEMO</h1>
<a href="http://gouji.org/" data-rss="http://gouji.org/rss.php">gouji.org</a>  <br>
<a href="http://www.asilu.com" data-rss="http://www.asilu.com/feed">www.asilu.com</a>  <br>

<script>
/* 简爱 2015/5/18 */
$('a[data-rss]').hover(function(){
		if(this.dialog){
			this.dialog.show(this);
			return false;
		}
		this.dialog = dialog({
			quickClose: true,
			cancelDisplay: false,
			cancel: function () {
				this.close();
				return false;
			}
		});
		var _this = this;
		this.dialog.show(_this);

		$.getJSON('http://query.yahooapis.com/v1/public/yql?format=json&callback=?&q=select * from rss where url="'+ $(_this).data('rss') +'"', function(j){
			if(j.query.results){
				items = j.query.results.item;
				_html = '';
				for(i=0, l=items.length; i < l; i++){
					item = items[i];
					_html += '<li class="demo_rss_li"><a target="_blank" href="'+ item.link +'">'+ item.title +'</a><span class="demo_rss_div">'+ item.description +'</span></li>';
				}
				_this.dialog.content(_html);
			}

		});
		return false;
	}
)
</script>

</body>
</html>


本文出自简爱博客,转载时请注明出处及相应链接。

    发表评论

    电子邮件地址不会被公开。必填项已用*标注