英文:
Saving RSS Feed history using =IMPORTFEED and a Google Sheets Script
问题
I am trying to build a database of the RSS Feed history of several feeds on Google Sheets. In order to do this, I am building on Digital Farmer's answer to the question Google sheet RSS feed automatically Update.
The provided answer retrieves only the article's title but I want to retrieve other valuable data like the article's url, the date, the feed's title and the feed's url.
The function Digital Farmer produced is as follows, which I have adapted to retrieve the data from the feeds I need:
function rssfeed() {
var ss = SpreadsheetApp.getActive();
//SiteOne
ss.getRange('Import RSS!A1').setFormula('=IMPORTFEED("https://e-ficiencia.com/feed/","items Title",False,100)');
ss.getRange('Import RSS!B1:B').copyTo(ss.getRange('History RSS!A1:A'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
ss.getRange('Import RSS!A1').clear({contentsOnly: true, skipFilteredRows: true});
//SiteTwo
ss.getRange('Import RSS!A1').setFormula('=IMPORTFEED("https://www.climanoticias.com/feed/all","items Title",False,100)');
ss.getRange('Import RSS!B1:B').copyTo(ss.getRange('History RSS!A1:A'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
ss.getRange('Import RSS!A1').clear({contentsOnly: true, skipFilteredRows: true});
//SiteThree
ss.getRange('Import RSS!A1').setFormula('=IMPORTFEED("https://www.proinstalaciones.com/actualidad/noticias?format=feed","items Title",False,100)');
ss.getRange('Import RSS!B1:B').copyTo(ss.getRange('History RSS!A1:A'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
ss.getRange('Import RSS!A1').clear({contentsOnly: true, skipFilteredRows: true});
}
Expected behavior
- Include other types of data: date, url, feed name, feed url
- Clearly identify which article comes from which feed
Here's a link to an open spreadsheet where change may be made.
英文:
I am trying to build a database of the RSS Feed history of several feeds on Google Sheets. In order to do this, I am building on Digital Farmer's answer to the question Google sheet RSS feed automatically Update.
The provided answer retrieves only the article's title but I want to retrieve other valuable data like the article's url, the date, the feed's title and the feed's url.
The function Digital Farmer produced is as follows, which I have adapted to retrieve the data from the feeds I need:
function rssfeed() {
var ss = SpreadsheetApp.getActive();
//SiteOne
ss.getRange('Import RSS!A1').setFormula('=IMPORTFEED("https://e-ficiencia.com/feed/","items Title",False,100)');
ss.getRange('Import RSS!B1:B').copyTo(ss.getRange('History RSS!A1:A'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
ss.getRange('Import RSS!A1').clear({contentsOnly: true, skipFilteredRows: true});
//SiteTwo
ss.getRange('Import RSS!A1').setFormula('=IMPORTFEED("https://www.climanoticias.com/feed/all","items Title",False,100)');
ss.getRange('Import RSS!B1:B').copyTo(ss.getRange('History RSS!A1:A'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
ss.getRange('Import RSS!A1').clear({contentsOnly: true, skipFilteredRows: true});
//SiteThree
ss.getRange('Import RSS!A1').setFormula('=IMPORTFEED("https://www.proinstalaciones.com/actualidad/noticias?format=feed","items Title",False,100)');
ss.getRange('Import RSS!B1:B').copyTo(ss.getRange('History RSS!A1:A'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
ss.getRange('Import RSS!A1').clear({contentsOnly: true, skipFilteredRows: true});
}
Expected behavior
- Include other types of data: date, url, feed name, feed url
- Clearly identify which article comes from which feed
Here's a link to an open spreadsheet where change may be made.
答案1
得分: 1
将以下内容翻译为中文:
"Getting Data from RSS feed to Google Sheet.
I am with @Cooper in terms of how to tackle or get your desired result. I would suggest using URL Fetch App and XML services to get the context you are looking for. I have created a sample to get you going. You can run this on your sample sheet so you can see, how it works and get you further on your project. I would also suggest headers as markers of the result.
Sample Code:
> Please keep in mind that there are still vague things on the data you
> want to get, this sample code you might need some modification to work
> with your project
function getURLData() {
var currentData = [];
var urltoCheck = ["https://e-ficiencia.com/feed/", "https://www.climanoticias.com/feed/all","https://www.proinstalaciones.com/actualidad/noticias?format=feed"];
for (var i = 0; i < urltoCheck.length; i++){
var ficiencaData = UrlFetchApp.fetch(urltoCheck[i]);
var xml = ficiencaData.getContentText()
let response = XmlService.parse(xml);
var root = response.getRootElement();
let channel = root.getChild('channel');
let items = channel.getChildren('item');
items.forEach(item => {
let title = item.getChild('title').getText();
let pubDateb = item.getChild('pubDate').getText();
let link = item.getChild('link').getText();
currentData.push([title,pubDateb,link,urltoCheck[i]])
});
}
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName("History RSS");
var currentDataRange = sheet.getRange(sheet.getLastRow() + 1, 1, currentData.length, currentData[0].length);
currentDataRange.setValues(currentData);
}"
这是翻译好的部分,代码部分不包括在内。
英文:
Getting Data from RSS feed to Google Sheet.
I am with @Cooper in terms of how to tackle or get your desired result. I would suggest using URL Fetch App and XML services to get the context you are looking for. I have created a sample to get you going. You can run this on your sample sheet so you can see, how it works and get you further on your project. I would also suggest headers as markers of the result.
Sample Code:
> Please keep in mind that there are still vague things on the data you
> want to get, this sample code you might need some modification to work
> with your project
function getURLData() {
var currentData = [];
var urltoCheck = ["https://e-ficiencia.com/feed/", "https://www.climanoticias.com/feed/all","https://www.proinstalaciones.com/actualidad/noticias?format=feed"];
for (var i = 0; i < urltoCheck.length; i++){
var ficiencaData = UrlFetchApp.fetch(urltoCheck[i]);
var xml = ficiencaData.getContentText()
let response = XmlService.parse(xml);
var root = response.getRootElement();
let channel = root.getChild('channel');
let items = channel.getChildren('item');
items.forEach(item => {
let title = item.getChild('title').getText();
let pubDateb = item.getChild('pubDate').getText();
let link = item.getChild('link').getText();
currentData.push([title,pubDateb,link,urltoCheck[i]])
});
}
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName("History RSS");
var currentDataRange = sheet.getRange(sheet.getLastRow() + 1, 1, currentData.length, currentData[0].length);
currentDataRange.setValues(currentData);
}
Here is how it should look like:
References:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论