김대선

정보 가져오는 기능 묶음, 불필요한 라우터 제거

const express = require('express')
const naverRouter = require('./router/naver')
const kakaoRouter = require('./router/kakao')
const programmersRouter = require('./router/programmers')
const functions = require('./function')
const app = express();
......@@ -12,10 +9,43 @@ const server = app.listen(3000,()=>{
console.log("app listening at http://%s:%s", host, port)
})
app.use('/naver', naverRouter)
app.use('/kakao', kakaoRouter)
app.use('/programmers', programmersRouter)
app.get('/', (req, res)=>{
res.send("this is home!")
app.get('/', async (req, res)=>{
let string = ""
let data = await functions.getKakaoData()
let temp = ""
for(let i of data){
temp = "title : " + i.title
string = string + temp + "\n"
temp = "tags : " + i.tags.toString()
string = string + temp + "\n"
temp = "url : " + i.url
string = string + temp + "\n"
}
data = await functions.getNaverFunction()
temp = ""
for(let i of data){
temp = "title : " + i.title
string = string + temp + "\n"
if(!!i.tags){
temp = "tags : " + i.tags.toString()
string = string + temp + "\n"
}
temp = "url : " + i.url
string = string + temp + "\n"
}
data = await functions.getProgrammersFunction()
temp = ""
for(let i of data){
temp = "title : " + i.title
string = string + temp + "\n"
temp = "tags : " + i.tags.toString()
string = string + temp + "\n"
temp = "url : " + i.url
string = string + temp + "\n"
}
res.send(string)
})
\ No newline at end of file
......
const kakaoFunction = require("./functions/kakaoFunction");
const naverFunction = require("./functions/naverFunction");
const programmersFunction = require("./functions/programmersFunction")
module.exports = {
getKakaoData : kakaoFunction.getData,
getNaverFunction : naverFunction.getData,
getProgrammersFunction : programmersFunction.getData
}
......@@ -19,7 +19,6 @@ const makeObject = (array)=>{
tempData = splitData(i)
result.push({
title : tempData[0],
term : tempData[2],
tags : [],
url : tempData[tempData.length - 1]
})
......@@ -34,9 +33,9 @@ const makeObject = (array)=>{
const moveNextPage = async (page)=>{
await page.click('#mArticle > div > div.paging_list > span > a:nth-child(11) > span > span').catch((error)=>{
await page.click('#mArticle > div > div.paging_list > span > a:nth-child(10) > span > span').catch((error)=>{
})
await page.waitForTimeout(300)
await page.waitForTimeout(1000)
return await page.content()
}
......
......@@ -20,7 +20,6 @@ const makeObject = (array)=>{
if(tempData.length == 5){
result.push({
title : tempData[0],
term : tempData[2],
tags : tempData[3].split('#').filter((ele)=>ele != ''),
url : tempData[4]
})
......@@ -28,7 +27,6 @@ const makeObject = (array)=>{
else if (tempData.length == 4){
result.push({
title : tempData[0],
term : tempData[2],
url : tempData[3]
})
}
......
......@@ -19,7 +19,6 @@ const makeObject = (array)=>{
tempData = splitData(i)
result.push({
title : tempData[0],
term : tempData[2],
tags : [],
url : tempData[tempData.length - 1]
})
......@@ -77,8 +76,7 @@ const getData = async ()=>{
return result
}
getData()
module.exports = {
getData : getData
}
\ No newline at end of file
......
const express = require('express')
const router = express.Router()
const kakaoFunction = require('./kakaoFunction')
router.get('/', (req, res, error)=>{
res.send('hello this is kakao')
})
router.get('/recruitment', async (req, res, error)=>{
res.send(await kakaoFunction.getData())
})
module.exports = router
\ No newline at end of file
const express = require('express')
const router = express.Router()
const naverFunction = require('./naverFunctions')
router.get('/', (req, res, error)=>{
res.send("naver home")
})
router.get('/recruitment', async (req, res, error)=>{
res.send(await naverFunction.getData())
})
module.exports = router
\ No newline at end of file
const express = require('express')
const router = express.Router()
const programmersFunction = require('./programmersFunction')
router.get('/', (req, res, error)=>{
res.send("programmers home")
})
router.get('/recruitment', async (req, res, error)=>{
res.send("this is programmers recruitment")
})
module.exports = router
\ No newline at end of file