강현태

getAllToons()추가 index에 모든 웹툰 출력

This diff is collapsed. Click to expand it.
...@@ -61,7 +61,6 @@ function getUpdatedToons(){ ...@@ -61,7 +61,6 @@ function getUpdatedToons(){
61 61
62 var toonName = link.text(); 62 var toonName = link.text();
63 var toonHref = link.attr('href'); 63 var toonHref = link.attr('href');
64 - console.log(toonName + ' -> ' + toonHref);
65 updatedToon[toonName]=toonHref; 64 updatedToon[toonName]=toonHref;
66 }); 65 });
67 66
...@@ -69,5 +68,33 @@ function getUpdatedToons(){ ...@@ -69,5 +68,33 @@ function getUpdatedToons(){
69 }); 68 });
70 } 69 }
71 70
71 +allWebtoons = getAllToons();
72 +function getAllToons() {
73 + var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn";
74 + allWebtoonJSONList = new Array();
75 + request(allWeeklyToonsUrl,function (err, res, html) {
76 + if(!err){
77 + var $ = cheerio.load(html);
78 + $(".thumb").each(function (i) {
79 + var week = $(this).parent().parent().prev().attr('class');
80 + var webtoon_link = "http://comic.naver.com" + $(this).children().first().attr('href');
81 + var thumb_link = $(this).children().first().children().first().attr('src');
82 + var name = $(this).next().text();
83 +
84 + var webtoon= {
85 + name : name,
86 + thum_link : thumb_link,
87 + webtoon_link : webtoon_link,
88 + week : week
89 + };
90 + webtoon_string = JSON.stringify(webtoon);
91 + //JSON으로 만든당.
92 + allWebtoonJSONList.push(webtoon_string);
93 + })
94 + }
95 + });
96 + return(allWebtoonJSONList);
97 +}
98 +
72 99
73 module.exports = app; 100 module.exports = app;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -6,7 +6,7 @@ router.get('/', function(req, res, next) { ...@@ -6,7 +6,7 @@ router.get('/', function(req, res, next) {
6 6
7 res.render('index', { 7 res.render('index', {
8 title: '니툰내툰', 8 title: '니툰내툰',
9 - list: updatedToon 9 + list: allWebtoons
10 }); 10 });
11 }); 11 });
12 12
......
...@@ -4,17 +4,40 @@ ...@@ -4,17 +4,40 @@
4 <title><%= title %></title> 4 <title><%= title %></title>
5 <link rel='stylesheet' href='/stylesheets/style.css' /> 5 <link rel='stylesheet' href='/stylesheets/style.css' />
6 </head> 6 </head>
7 - <body>
8 <h1><%= title %></h1> 7 <h1><%= title %></h1>
9 <p><%= title %></p> 8 <p><%= title %></p>
9 +
10 + <table>
10 <% 11 <%
11 - for(name in list){ 12 + var current = "";
12 - %> 13 + for(jsonString in list){
13 - <%= name+ "=" + list[name] %> 14 + var A=JSON.parse(list[jsonString]);
14 - </br> 15 + if(current!=A.week){
16 + if(current!=""){
17 + %>
18 + </tr>
19 + <% } %>
20 + <tr>
21 + <th><%= A.week %></th>
22 + <% } %>
23 + <td>
24 + <a href="<%= A.webtoon_link %>">
25 + <img src="<%= A.thum_link %>"/>
26 + </a>
27 + <%= A.name %>
28 + </td>
29 + <%
30 + if(current!=A.week) {
31 + current = A.week;
32 + %>
33 +
15 <% 34 <%
16 } 35 }
36 + }
17 %> 37 %>
18 - <br> 38 + </tr>
39 + </table>
40 + </br>
41 +
19 </body> 42 </body>
20 </html> 43 </html>
......