Skip to content

Instantly share code, notes, and snippets.

@cmbaughman
Created March 5, 2014 16:02
Show Gist options
  • Save cmbaughman/9370106 to your computer and use it in GitHub Desktop.
Save cmbaughman/9370106 to your computer and use it in GitHub Desktop.
Parse RSS feed as JSON from client using Google API
var rssUrl = "http://www.exploit-db.com/rss.xml";
function parseRSS(url, callback) {
$.ajax({
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
success: function(data) {
callback(data.responseData.feed.entries);
}
});
}
html = "";
parseRSS(rssUrl, function(rss) {
for(i = rss.length-1; i >=0; i--) {
html += "<p><a href='" + rss[i].link + "'>" + rss[i].title + "</a></p>";
}
$("div#target").html(html);
});
@djprmf
Copy link

djprmf commented Jan 21, 2016

@molayli
Copy link

molayli commented Feb 11, 2017

here is an updated version using rss2json.com api

<html>
<head>
  <title>GetRSSFeed</title>
</head>
<body>
<div id="target"></div>

<script src="https://code.jquery.com/jquery-2.2.4.min.js" ></script>
<script>
  var rssUrl = "http://www.exploit-db.com/rss.xml";
  function parseRSS(url, callback) {
    $.ajax({
      url: 'https://api.rss2json.com/v1/api.json?rss_url=' + encodeURIComponent(url),
      dataType: 'json',
      success: function(data) {
        callback(data);
      }
    });
  }
  html = "";
  parseRSS(rssUrl, function(rss) {
      var items = rss.items;
      for(i = items.length-1; i >=0; i--) {
            html += "<p><a href='" + items[i].link + "'>" + items[i].title + "</a></p>";  
      }
    $("div#target").html(html);
  });
</script>
</body>
</html>

@cmbaughman
Copy link
Author

That's awesome! Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment