app.js
2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
let express = require('express');
let app = express();
let request = require('request');
const asyncHandler = require('express-async-handler')
const { response } = require('express');
const puppeteer = require('puppeteer');
const cheerio = require('cheerio');
const { textContent } = require('domutils');
app.get('/LotteCinema', asyncHandler(async (req, res, next) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// 수집하고자 하는 URL을 입력
await page.goto('https://www.lottecinema.co.kr/NLCHS/Movie/List?flag=1');
let content = await page.content();
let $ = cheerio.load(content, {decodeEntities: true});
let data = [];
const $bodyList = $("#contents > div > ul.movie_list.type2").children("li");
let i =0;
$bodyList.each(function(elem){
if($(this).find('a > em').text() != "AD"){
data[i++]={
rank : i,
url: $(this).find('div.top_info > div > div > a').attr('href'),
title : $(this).find(' div.btm_info > strong').text(),
rate : $(this).find('div.btm_info > span > span.rate_info > em').text(),
star : $(this).find('div.btm_info > span > span.star_info').text(),
};
}
});
await browser.close();
res.send(data);
//console.log(data);
}))
app.get('/LotteCinema/theater', asyncHandler(async (req, res, next) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// 수집하고자 하는 URL을 입력
await page.goto('https://www.lottecinema.co.kr/NLCHS/');
let content = await page.content();
let $ = cheerio.load(content, {decodeEntities: true});
let theaterData = [];
const $TypeList = $("#nav > ul > li:nth-child(3) > div > ul").children("li").find("div > ul").children("li");
let i =0;
let flag = 0;
$TypeList.each(function(temp_Type){
if(flag==1){
theaterData[i++]={
LocateUrl : $(this).find('a').attr('href'),
LocateName : $(this).find('a').text(),
LocateQuery : $(this).find('a').attr('href')
.replace("https://www.lottecinema.co.kr/NLCHS/Cinema/Detail?divisionCode=","")
.replace("https://www.lottecinema.co.kr/NLCHS/Cinema/SpecialCinema?divisionCode=","")
.replace("&detailDivisionCode=","|").replace("&cinemaID=","|").replace("&screendivcd=","|"),
};
}else{
flag++;
}
});
await browser.close();
res.send(theaterData);
//console.log(theaterData);
}))
let server = app.listen(80);