【问题标题】:How to parse the title of each item of a feed in Google Apps Scripts如何在 Google Apps 脚本中解析提要的每个项目的标题
【发布时间】:2022-09-23 20:08:39
【问题描述】:

我尝试简单地解析一个 RSS 提要,但我得到一个错误。我怎样才能得到每个项目的“标题”? 它说\“无法读取属性\'getText\' of null\”

我不知道如何调试它。

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);
});

}

    标签: google-apps-script rss feed


    【解决方案1】:

    当你的放映脚本被修改时,下面的修改怎么样?

    从:

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

    至:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2018-03-22
      • 2014-12-19
      • 1970-01-01
      相关资源
      最近更新 更多