김대선

데이터 추출 및 분류 기능을 함수로 분리

...@@ -39,11 +39,7 @@ const makeObject = (array)=>{ ...@@ -39,11 +39,7 @@ const makeObject = (array)=>{
39 return result 39 return result
40 } 40 }
41 41
42 -router.get('/', (req, res, error)=>{ 42 +const getData = async ()=>{
43 - res.send("naver home")
44 -})
45 -
46 -router.get('/recruitment', async (req, res, error)=>{
47 const browser = await puppeteer.launch(); 43 const browser = await puppeteer.launch();
48 const page = await browser.newPage(); 44 const page = await browser.newPage();
49 45
...@@ -57,7 +53,7 @@ router.get('/recruitment', async (req, res, error)=>{ ...@@ -57,7 +53,7 @@ router.get('/recruitment', async (req, res, error)=>{
57 await page.click('#moreDiv > button').catch((error)=>{ 53 await page.click('#moreDiv > button').catch((error)=>{
58 54
59 }) 55 })
60 - await page.waitForTimeout(300) 56 + await page.waitForTimeout(200)
61 content = await page.content() 57 content = await page.content()
62 } 58 }
63 } 59 }
...@@ -73,7 +69,15 @@ router.get('/recruitment', async (req, res, error)=>{ ...@@ -73,7 +69,15 @@ router.get('/recruitment', async (req, res, error)=>{
73 resArr = result.split('</li><li>') 69 resArr = result.split('</li><li>')
74 result = makeObject(resArr) 70 result = makeObject(resArr)
75 console.log(result) 71 console.log(result)
76 - res.send(result) 72 + return result;
73 +}
74 +
75 +router.get('/', (req, res, error)=>{
76 + res.send("naver home")
77 +})
78 +
79 +router.get('/recruitment', async (req, res, error)=>{
80 + res.send(await getData())
77 }) 81 })
78 82
79 83
......