function importRssFeed() {
const feedUrl = 'https://example.com/feed.xml'; // сюда вставить RSS
const sheetName = 'RSS';
const ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName(sheetName);
if (!sheet) {
sheet = ss.insertSheet(sheetName);
}
sheet.clearContents();
sheet.appendRow(['Дата', 'Заголовок', 'Ссылка', 'Описание']);
const xmlText = UrlFetchApp.fetch(feedUrl).getContentText();
const document = XmlService.parse(xmlText);
const root = document.getRootElement();
const channel = root.getChild('channel');
const items = channel.getChildren('item');
items.forEach(item => {
const title = getText(item, 'title');
const link = getText(item, 'link');
const pubDate = getText(item, 'pubDate');
const description = stripHtml(getText(item, 'description'));
sheet.appendRow([pubDate, title, link, description]);
});
}
function getText(item, tagName) {
const child = item.getChild(tagName);
return child ? child.getText() : '';
}
function stripHtml(html) {
return html ? html.replace(/<[^>]*>/g, '').trim() : '';
}