Last active
April 17, 2018 04:10
-
-
Save antonybudianto/bc6ac522d556344b2c24f57a92171ada to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch('https://www.tokopedia.com/blog/search/keuangan/feed/rss2/').then(a => a.text()).then(txt => { | |
let parser = new DOMParser(); | |
let res = parser.parseFromString(txt, 'text/xml'); | |
let arr = []; | |
let doc = res.getElementsByTagName('item'); | |
let fields = ['title', 'description', 'link', 'pubDate']; | |
for (let i=0;i<doc.length;i++) { | |
let obj = {}; | |
let cats = []; | |
let catDoc = doc[i].getElementsByTagName('category'); | |
for (let j = 0; j < catDoc.length; j++) { | |
cats.push(catDoc[j].textContent); | |
} | |
obj.cats = cats; | |
fields.map(f => { | |
let val = doc[i].getElementsByTagName(f)[0].textContent; | |
obj[f] = val; | |
}); | |
arr.push(obj); | |
} | |
console.log(arr); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment