2013-11-22 192 views
0
This is my code, I want to find all the rss feeds present in But this is not working, can some one help me in this. 

当我尝试执行此操作时,它会给出一个空白页。请帮我解决这个问题。使用良好的饲料api找到rss饲料

我发现了类似的代码解析RSS饲料,我刚刚修改它,我认为它应该工作。但是ID不适合我。

<html> 
<head> 
<script type="text/javascript" src="https://www.google.com/jsapi"></script> 
<script type="text/javascript"> 

google.load("feeds", "1"); 

function initialize() { 
    /// Here is the place I give my site name 
    var feed = new google.feeds.findFeeds("http://timesofindia.indiatimes.com/"); 
    feed.load(function(result) { 
    if (!result.error) { 
     var container = document.getElementById("feed"); 
     for (var i = 0; i < result.feed.entries.length; i++) { 
     var entry = result.feed.entries[i]; 
     var div = document.createElement("div"); 
     div.appendChild(document.createTextNode(entry.title)); 
     container.appendChild(div); 
     } 
    } 
    }); 
} 
google.setOnLoadCallback(initialize); 

</script> 
</head> 
<body> 
    /// This is div where rss feed come and display in UI 
<div id="feed"></div> 
</body> 
</html> 

回答

0

嗯检查下面的代码:

HTML代码:

<!doctype html> 
<html lang="en"> 
<head> 
<meta charset="UTF-8"> 
<title>Google Feed</title> 
<script type="text/javascript" src="https://www.google.com/jsapi"></script> 
<script type="text/javascript"> 
    google.load("feeds", "1"); 
    function initialize() { 
    // Change your code with 
    var feed = new google.feeds.Feed("http://timesofindia.feedsportal.com/c/33039/f/533916/index.rss"); 
    // Because, findFeeds is a Callback method which is filter the result after feed query complete. 
    // Second thing you are using normal website URL not feed url. So, change your URL too 
    /// Here is the place I give my site name 
    var feed = new google.feeds.findFeeds("http://timesofindia.indiatimes.com/"); 
    feed.load(function(result) { 
     if (!result.error) { 
      var container = document.getElementById("feed"); 
      for (var i = 0; i < result.feed.entries.length; i++) { 
       var entry = result.feed.entries[i]; 
       var div = document.createElement("div"); 
       div.appendChild(document.createTextNode((i+1) + ': ' + entry.title)); 
       container.appendChild(div); 
      } 
     } 
    }); 
} 
google.setOnLoadCallback(initialize); 
</script> 
</head> 
<body> 
<h4> This is div where rss feed come and display in UI </h4> 
<div id="feed"> 
</div> 
</body> 
</html> 

建议:

第一: 使用饲料代替findFeeds

二: 使用RSS网址

+0

其中以RSS URL你在说什么,我试图让所有的RSS网址在timesofindia.indiatimes.com本网站 – user2964771