Home > Blockchain >  How to parse the title of each item of a feed in Google Apps Scripts
How to parse the title of each item of a feed in Google Apps Scripts

Time:09-24

I try to simply parse a RSS feed, but i get an error. How can i get the "Title" of each item? It says "Cannot read property 'getText' of null"

I have no clue how i can debug this.

function parseFeed() {
  var feed = UrlFetchApp.fetch("https://www.reddit.com/r/GoogleAppsScript.rss?limit=1000").getContentText();
  feed = XmlService.parse(feed);

  var namespace = XmlService.getNamespace("http://www.w3.org/2005/Atom");
  var items = feed.getRootElement().getChildren("entry", namespace);  

items.forEach(item => {
    var title = item.getChild('title').getText();
    Logger.log(title);
});

}

CodePudding user response:

When your showing script is modified, how about the following modification?

From:

var title = item.getChild('title').getText();

To:

var title = item.getChild('title', namespace).getText();
  • Related