Created
January 27, 2020 10:48
-
-
Save masatomix/07b00579d41da816bb26cf1eb21e15b5 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
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