You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用=IMPORTFEED和Google Sheets脚本保存RSS Feed历史记录

多RSS Feed历史数据库的Google Sheets实现方案

之前基于Digital Farmer的《Google Sheet RSS Feed自动更新》方案开发,但原代码只能抓取文章标题,现在需要扩展功能,抓取文章URL、发布日期、Feed标题、Feed URL,同时明确每篇文章的Feed来源。

修改后的完整代码

function rssfeed() {
  const ss = SpreadsheetApp.getActive();
  const importSheet = ss.getSheetByName('Import RSS');
  const historySheet = ss.getSheetByName('History RSS');
  
  // 配置所有需要抓取的RSS源,包含Feed名称和URL
  const rssFeeds = [
    {name: 'E-ficiencia', url: 'https://e-ficiencia.com/feed/'},
    {name: 'Clima Noticias', url: 'https://www.climanoticias.com/feed/all'},
    {name: 'Proinstalaciones', url: 'https://www.proinstalaciones.com/actualidad/noticias?format=feed'}
  ];

  // 遍历每个RSS源
  rssFeeds.forEach(feed => {
    // 清空临时表数据
    importSheet.clear({contentsOnly: true, skipFilteredRows: true});
    
    // 导入完整的RSS条目数据(包含标题、链接、发布日期等)
    importSheet.getRange('A1').setFormula(`=IMPORTFEED("${feed.url}", "items", FALSE, 100)`);
    SpreadsheetApp.flush(); // 等待公式执行完成
    
    // 获取导入的有效数据范围(跳过表头)
    const dataRange = importSheet.getDataRange().offset(1, 0);
    const values = dataRange.getValues();
    
    // 过滤空行,添加Feed名称和Feed URL字段
    const processedData = values.filter(row => row[0] !== '')
      .map(row => [
        row[0], // 文章标题
        row[1], // 文章URL
        row[2], // 发布日期
        feed.name, // Feed名称
        feed.url // Feed URL
      ]);
    
    // 将处理后的数据追加到历史表末尾
    if (processedData.length > 0) {
      historySheet.getRange(historySheet.getLastRow() + 1, 1, processedData.length, 5).setValues(processedData);
    }
  });
  
  // 最后清空临时表
  importSheet.clear({contentsOnly: true, skipFilteredRows: true});
}

功能说明

  • 字段完整性:每篇文章会记录:文章标题、文章URL、发布日期、Feed名称、Feed URL
  • 来源明确:通过手动配置的feed.name和feed.url直接标记每篇文章的所属RSS源
  • 自动追加:新抓取的数据会自动添加到History RSS表的末尾,不会覆盖原有历史数据
  • 临时表复用:使用Import RSS工作表作为临时数据存储,避免多个公式同时运行冲突

使用注意事项

  • 确保你的Google Sheets中有Import RSS和History RSS两个工作表
  • 首次运行时,需要授权脚本访问你的Google Sheets和网络资源
  • 可以通过添加更多对象到rssFeeds数组来扩展需要抓取的RSS源
  • 如果需要去重,可以在追加数据前添加逻辑,对比历史表中的文章URL避免重复插入

内容的提问来源于stack exchange,提问作者djur

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 00:37:47