전세계

기능: 크롤링한 데이터를 data.json으로 저장

1 node_modules 1 node_modules
2 -package-lock.json
...\ No newline at end of file ...\ No newline at end of file
2 +package-lock.json
3 +data.json
...\ No newline at end of file ...\ No newline at end of file
......
1 +const fs = require('fs');
1 const express = require('express'); 2 const express = require('express');
2 const app = express(); 3 const app = express();
3 const port = 80; 4 const port = 80;
...@@ -18,6 +19,10 @@ const getHTML = async () => { ...@@ -18,6 +19,10 @@ const getHTML = async () => {
18 19
19 getHTML() 20 getHTML()
20 .then(html => { 21 .then(html => {
22 + var today = new Date();
23 + var dateInfo = `${today.getFullYear()}/${today.getMonth() + 1}/${today.getDate()}`;
24 + fakerData['date'] = dateInfo;
25 +
21 const $ = cheerio.load(html.data); 26 const $ = cheerio.load(html.data);
22 27
23 //#region LCK 통산 전적 28 //#region LCK 통산 전적
...@@ -138,10 +143,13 @@ getHTML() ...@@ -138,10 +143,13 @@ getHTML()
138 143
139 fakerData['champions'] = championData; 144 fakerData['champions'] = championData;
140 //#endregion 145 //#endregion
141 - 146 +
142 return fakerData; 147 return fakerData;
143 }) 148 })
144 - .then(res => console.log(res)); 149 + .then(res => {
150 + console.log(res)
151 + fs.writeFileSync('data.json', JSON.stringify(res));
152 + });
145 153
146 app.get('/', (req, res) => { 154 app.get('/', (req, res) => {
147 res.send('Express Test'); 155 res.send('Express Test');
......