Parse Stack Exchange RSS Feeds

This Google Script will fetch and parse the XML RSS Feeds of any Stack Exchange website. You can then use the MailApp service to automatically push the content of the RSS feed to another email address on a regular basis. Or you can build an RSS to email service using Google Scripts.

function parseXML() {
  var feed = 'http://stackexchange.com/feeds';

  var xml = UrlFetchApp.fetch(feed).getContentText();
  var root = XmlService.parse(xml).getRootElement();
  var atom = XmlService.getNamespace('http://www.w3.org/2005/Atom');

  var entries = root.getChildren('entry', atom);

  for (var i = 0; i < entries.length; i++) {
    var title = entries[i].getChild('title', atom).getText();
    var categoryElements = entries[i].getChildren('category', atom);

    var updated = entries[i].getChild('updated', atom).getValue();
    var url = entries[i].getChild('id', atom).getValue();
    var summary = entries[i].getChild('summary', atom).getText();
    var user = entries[i].getChildren('author', atom)[0].getChild('name', atom).getValue();
    var userURL = entries[i].getChildren('author', atom)[0].getChild('uri', atom).getValue();

    var regexSubSite = /http:\/\/(.*?).stackexchange\.com/.exec(url);
    var site, siteURL;

    if (!regexSubSite) {
      // If it's not a "subsite"...
      site = /http:\/\/(.*)\.com/.exec(url);
      site = site ? site[1] : 'noneFound';
      siteURL = site ? 'http://www.' + site + '.com' : 'noneFound';
    } else {
      site = regexSubSite[1];
      siteURL = regexSubSite[0];
    }

    // url     - Question URL
    // title   - Question Title
    // user    - Question Author
    // userURL - Author Profile URL
    // site    - Stack Exchange Site Name
    // siteURL - SE Site URL
  }
}
Amit Agarwal

Amit Agarwal

Google Developer Expert, Google Cloud Champion

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.

Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

0

Awards & Titles

Digital Inspiration has won several awards since it's launch in 2004.

Google Developer Expert

Google Developer Expert

Google awarded us the Google Developer Expert award recogizing our work in Google Workspace.

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards in 2017.

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional (MVP) title for 5 years in a row.

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator title recognizing our technical skill and expertise.

Email Newsletter

Sign up for our email newsletter to stay up to date.

We will never send any spam emails. Promise.