[英]How to get the description of a news Item from GOOGLE AJAX Feed API
[英]Parse JSON for clean, pure text of the description in Google News feed
我想檢索已經使用Google AJAX API處理的Google新聞RSS Feed中找到的故事description
的純文本(沒有任何HTML),以將RSS轉換為JSON。 如何解析“JSON'd”提要以獲取干凈的description
/ content
文本,如下面的第二個屏幕截圖所示?
截圖:
raw 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>');
});
});
演示: http : //jsfiddle.net/h4H4p/
JSON不是Javascript,因此您可以像訪問簡單的Javascript對象一樣訪問JSON數據。 所以你的描述是在NAME_OF_YOUR_JSON_VAR.value.description
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.