我想检索在 Google 新闻 RSS 提要上找到的故事的描述
的纯文本(没有任何 HTML),该提要已使用 Google AJAX API 处理以将 RSS 转换为 JSON。 如何解析“JSON 格式”提要以获得干净的 description
/content
文本,如下面的第二个屏幕截图所示?
截图:
原始 rss:http://i.imgur.com/UmiIK.jpg
通过 Y 的漂亮、干净的描述!管道:http://i.imgur.com/MFIB6.jpg
JSFiddle:http://jsfiddle.net/KuLQw/1/
可以在 description
/content
上使用 $.text(),但是如何删除最后多余的相关废话? (请参阅下面对答案的评论)
$.getJSON('http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=100&callback=?&q=http%3A%2F%2Fnews.google.com%2F%3Foutput%3Drss', function(data){
$.each(data.responseData.feed.entries, function(i, item){
// variables
var title = item.title;
var url = item.link;
var pub_date = item.pubDate;
var description = item.content;
// rendering
$('div.news').append('<div class="news-story"><p><a href="'+url+'">'+title+'</a></p><div style="border: 1px solid red">'+$(item.content).text()+'</div></div>');
});
});
最佳答案
这是一个开始:
var url='http://pipes.yahoo.com/pipes/pipe.run?_id=2FV68p9G3BGVbc7IdLq02Q&_render=json&feedcount=10&feedurl=http%3A%2F%2Fnews.google.com%2F%3Foutput%3Drss';
$.getJSON(url+'&_callback=?',function(x){
$.each(x.value.items,function(k,v){
$('#out').append('<div>'+v.title+'</div>');
});
});
关于javascript - 解析 JSON 以获取 Google News Feed 中描述的干净、纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9899537/