Home > OS >  How can I merge list of rss channels item to one page instead of each channel in one page?
How can I merge list of rss channels item to one page instead of each channel in one page?

Time:07-06

In the image shows a list of rss channels and they display only each channel in the page and I want to merge all the rss channels to one page

const urlsData = ['example1.xml','channel2.xml','example3.xml']
for (var ii = 0; ii < urlsData.length; ii  ) {
    Promise.all(fetch('https://rss.app/feeds/' urlsData[ii])
      .then(response => response.text())
      .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
      .then(data => {
        this.xmlContent = [].slice.call([...data.getElementsByTagName('item')])
console.log(this.xmlContect)
})

CodePudding user response:

The idea of Promise.all is to get as argument an array of ... promises? Anyhow this should work (tested).

import fetch from 'node-fetch';
import DomParser from 'dom-parser';
var parser = new DomParser();

const urlsData = ['http://www.ynet.co.il/Integration/StoryRss2.xml', 'http://www.ynet.co.il/Integration/StoryRss544.xml'];

var total = [];

Promise.all(urlsData.map(u => fetch(u)
    .then(response => response.text())
    .then(str => parser.parseFromString(str, "text/xml"))
    .then(data => total.push(...data.getElementsByTagName('item'))))
).then(() => {
    console.log(total)
})
  • Related