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