Skip to content

Instantly share code, notes, and snippets.

@masatomix
Created January 27, 2020 10:48
Show Gist options
  • Save masatomix/07b00579d41da816bb26cf1eb21e15b5 to your computer and use it in GitHub Desktop.
Save masatomix/07b00579d41da816bb26cf1eb21e15b5 to your computer and use it in GitHub Desktop.
const request = require('request')
const url = 'https://rss.techplay.jp/event/w3c-rss-format/rss.xml'
request(url, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
const regex = /[\b]/
body = body.replace(regex)
const json = xml2json(body)
// for (var i in json.rss.channel.item) {
// console.log('title:' + json.rss.channel.item[i].title)
// console.log('date :' + json.rss.channel.item[i].pubDate)
// }
console.log(JSON.stringify(json))
}
})
// const fs = require('fs');
// let body = fs.readFileSync("result.xml","UTF-8");
// // console.log(body);
// const json = xml2json(body)
// console.log(JSON.stringify(json))
function xml2json(body) {
return JSON.parse(require('xml2json').toJson(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment