Showing
3 changed files
with
35 additions
and
16 deletions
| ... | @@ -12,18 +12,23 @@ Graphic_card_info[0] = { | ... | @@ -12,18 +12,23 @@ Graphic_card_info[0] = { |
| 12 | "price" : 0, | 12 | "price" : 0, |
| 13 | "link" : "" | 13 | "link" : "" |
| 14 | } | 14 | } |
| 15 | -var count = 20; | 15 | +var count = 50; |
| 16 | 16 | ||
| 17 | request(url, function(error, response, html){ | 17 | request(url, function(error, response, html){ |
| 18 | if(!error){ | 18 | if(!error){ |
| 19 | var $ = cheerio.load(html); | 19 | var $ = cheerio.load(html); |
| 20 | + var i = 0; | ||
| 20 | $('ul.chartlist > li > a').each(function(){ | 21 | $('ul.chartlist > li > a').each(function(){ |
| 21 | info = new Object(); | 22 | info = new Object(); |
| 22 | var data = $(this); | 23 | var data = $(this); |
| 23 | info.name = data.find("span.prdname").text(); | 24 | info.name = data.find("span.prdname").text(); |
| 24 | - info.price = data.find("span.price-neww").text(); | 25 | + info.price = Number(data.find("span.price-neww").text().split(',').join('')); |
| 25 | info.link = data.attr("href"); | 26 | info.link = data.attr("href"); |
| 26 | Graphic_card_info.push(info); | 27 | Graphic_card_info.push(info); |
| 28 | + i++ | ||
| 29 | + if(i >= count){//50개만 저장 | ||
| 30 | + return false; | ||
| 31 | + } | ||
| 27 | }) | 32 | }) |
| 28 | 33 | ||
| 29 | 34 | ||
| ... | @@ -40,20 +45,34 @@ router.get('/',function(req,res){ | ... | @@ -40,20 +45,34 @@ router.get('/',function(req,res){ |
| 40 | 45 | ||
| 41 | router.get('/rank',function(req,res){ | 46 | router.get('/rank',function(req,res){ |
| 42 | console.log('Rank page'); | 47 | console.log('Rank page'); |
| 43 | - res.render('index',{ | 48 | + res.render('rank',{ |
| 44 | - graphic_card_info : Graphic_card_info | 49 | + graphic_card_info : Graphic_card_info, |
| 50 | + count : count | ||
| 45 | }); | 51 | }); |
| 46 | }); | 52 | }); |
| 47 | 53 | ||
| 48 | -router.post('/main',function(req,res,next){ | 54 | +router.post('/search',function(req,res,next){ |
| 49 | - console.log("Money"); | 55 | + console.log('Money : ' + req.body.money); |
| 50 | - res.send('Money : ' + req.body.money); | 56 | + var Money = req.body.money; |
| 51 | - console.log('Money : ' + req.body.money); | 57 | + var Searchlist = new Array(); |
| 52 | - /* | 58 | + var Searchcount = 0; |
| 53 | - res.render('main',{}); | 59 | + Searchlist[0] = { |
| 54 | - var money = req.body.money; | 60 | + "name" : "", |
| 55 | - console.log(money);*/ | 61 | + "price" : 0, |
| 56 | - //res.send(money); | 62 | + "link" : "" |
| 63 | + }; | ||
| 64 | + for(var i = 1; i <= count; i++){ | ||
| 65 | + if(Graphic_card_info[i].price <= Money){ | ||
| 66 | + Searchlist.push(Graphic_card_info[i]); | ||
| 67 | + Searchcount++; | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + res.render('index',{ | ||
| 72 | + money: Money, | ||
| 73 | + searchlist : Searchlist, | ||
| 74 | + count : Searchcount | ||
| 75 | + }); | ||
| 57 | }); | 76 | }); |
| 58 | 77 | ||
| 59 | 78 | ... | ... |
| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | <html> | 2 | <html> |
| 3 | <body> | 3 | <body> |
| 4 | <h1>OSS TermProject-컴퓨터 부품 추천</h1> | 4 | <h1>OSS TermProject-컴퓨터 부품 추천</h1> |
| 5 | - <form method="POST" action="http://localhost:3000/main"> | 5 | + <form method="POST" action="http://localhost:3000/search"> |
| 6 | <input type="text" name="money" placeholder="예산을 입력하세요($)."> | 6 | <input type="text" name="money" placeholder="예산을 입력하세요($)."> |
| 7 | <input type="submit" value="확인"> | 7 | <input type="submit" value="확인"> |
| 8 | </form> | 8 | </form> | ... | ... |
| 1 | <!DOCTYPE html> | 1 | <!DOCTYPE html> |
| 2 | <html> | 2 | <html> |
| 3 | <body> | 3 | <body> |
| 4 | - <%for(var i =1; i<=20;i++){%> | 4 | + <%for(var i =1; i<=count;i++){%> |
| 5 | <%= i + "." + graphic_card_info[i].name+" - ("+graphic_card_info[i].price+"$)"%> | 5 | <%= i + "." + graphic_card_info[i].name+" - ("+graphic_card_info[i].price+"$)"%> |
| 6 | - <%var link = "http://www.videocardbenchmark.net/"+graphic_card_info[i].link.toString() %>> | 6 | + <%var link = "http://www.videocardbenchmark.net/"+graphic_card_info[i].link.toString() %> |
| 7 | <a href = <%=link%> target=_blank>link</a> | 7 | <a href = <%=link%> target=_blank>link</a> |
| 8 | <br> | 8 | <br> |
| 9 | <%}%> | 9 | <%}%> | ... | ... |
-
Please register or login to post a comment