강현태

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

This diff is collapsed. Click to expand it.
......@@ -61,7 +61,6 @@ function getUpdatedToons(){
var toonName = link.text();
var toonHref = link.attr('href');
console.log(toonName + ' -> ' + toonHref);
updatedToon[toonName]=toonHref;
});
......@@ -69,5 +68,33 @@ function getUpdatedToons(){
});
}
allWebtoons = getAllToons();
function getAllToons() {
var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn";
allWebtoonJSONList = new Array();
request(allWeeklyToonsUrl,function (err, res, html) {
if(!err){
var $ = cheerio.load(html);
$(".thumb").each(function (i) {
var week = $(this).parent().parent().prev().attr('class');
var webtoon_link = "http://comic.naver.com" + $(this).children().first().attr('href');
var thumb_link = $(this).children().first().children().first().attr('src');
var name = $(this).next().text();
var webtoon= {
name : name,
thum_link : thumb_link,
webtoon_link : webtoon_link,
week : week
};
webtoon_string = JSON.stringify(webtoon);
//JSON으로 만든당.
allWebtoonJSONList.push(webtoon_string);
})
}
});
return(allWebtoonJSONList);
}
module.exports = app;
\ No newline at end of file
......
......@@ -6,7 +6,7 @@ router.get('/', function(req, res, next) {
res.render('index', {
title: '니툰내툰',
list: updatedToon
list: allWebtoons
});
});
......
......@@ -4,17 +4,40 @@
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1><%= title %></h1>
<p><%= title %></p>
<table>
<%
for(name in list){
var current = "";
for(jsonString in list){
var A=JSON.parse(list[jsonString]);
if(current!=A.week){
if(current!=""){
%>
<%= name+ "=" + list[name] %>
</br>
</tr>
<% } %>
<tr>
<th><%= A.week %></th>
<% } %>
<td>
<a href="<%= A.webtoon_link %>">
<img src="<%= A.thum_link %>"/>
</a>
<%= A.name %>
</td>
<%
if(current!=A.week) {
current = A.week;
%>
<%
}
}
%>
<br>
</tr>
</table>
</br>
</body>
</html>
......