임승현

Solve some issues

...@@ -3,19 +3,19 @@ import org.jsoup.nodes.Document; ...@@ -3,19 +3,19 @@ import org.jsoup.nodes.Document;
3 import org.jsoup.nodes.Element; 3 import org.jsoup.nodes.Element;
4 import org.jsoup.select.Elements; 4 import org.jsoup.select.Elements;
5 5
6 -import java.awt.*;
7 -import java.io.*;
8 -import java.net.URI;
9 -import java.net.URISyntaxException;
10 -import java.util.*;
11 -import java.util.List;
12 -
13 import org.openqa.selenium.By; 6 import org.openqa.selenium.By;
14 import org.openqa.selenium.WebDriver; 7 import org.openqa.selenium.WebDriver;
15 import org.openqa.selenium.WebElement; 8 import org.openqa.selenium.WebElement;
16 import org.openqa.selenium.chrome.ChromeDriver; 9 import org.openqa.selenium.chrome.ChromeDriver;
17 import org.openqa.selenium.chrome.ChromeOptions; 10 import org.openqa.selenium.chrome.ChromeOptions;
18 11
12 +import java.awt.*;
13 +import java.io.IOException;
14 +import java.net.URI;
15 +import java.net.URISyntaxException;
16 +import java.util.List;
17 +import java.util.*;
18 +
19 class CGVMovieInfo { //CGV 영화 정보를 담는 class 19 class CGVMovieInfo { //CGV 영화 정보를 담는 class
20 private String title; //영화 제목 20 private String title; //영화 제목
21 private int rank; //CGV 내 예매율 순위 21 private int rank; //CGV 내 예매율 순위
......
...@@ -17,7 +17,7 @@ const By = webdriver.By; ...@@ -17,7 +17,7 @@ const By = webdriver.By;
17 app.use(bodyParser.urlencoded({ extended: false })); 17 app.use(bodyParser.urlencoded({ extended: false }));
18 app.use(bodyParser.json()); 18 app.use(bodyParser.json());
19 19
20 -const url_movies = "https://www.cgv.co.kr/movies/?lt=1&ft=1"; //끝의 쿼리 0은 개봉 전 영화도 포함하는 것. 예매율 순위 가져오기 20 +const url_movies = "https://www.cgv.co.kr/movies/?lt=1&ft=0"; //끝의 쿼리 0은 개봉 전 영화도 포함하는 것. 예매율 순위 가져오기
21 const url_theaters = "https://www.cgv.co.kr/theaters"; //영화관 정보 가져오는 링크. 21 const url_theaters = "https://www.cgv.co.kr/theaters"; //영화관 정보 가져오는 링크.
22 const url_ticketing = "https://www.cgv.co.kr/ticket/"; //상영중인 영화 정보 가져오는 링크. 22 const url_ticketing = "https://www.cgv.co.kr/ticket/"; //상영중인 영화 정보 가져오는 링크.
23 23
...@@ -62,29 +62,42 @@ async.waterfall([ ...@@ -62,29 +62,42 @@ async.waterfall([
62 const driver_theaters = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build(); 62 const driver_theaters = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
63 driver_theaters.get(url_theaters); 63 driver_theaters.get(url_theaters);
64 //영화관 및 영화관에 대응되는 영화관별 고유 코드 가져오기. 64 //영화관 및 영화관에 대응되는 영화관별 고유 코드 가져오기.
65 - let area = await driver_theaters.wait(until.elementsLocated(By.className("area"))); 65 + let selector = '#contents > div.sect-common > div > div.sect-city > ul > li:nth-child({}) > div > ul > li > a';
66 - for (const elem of area) { 66 + let area = [];
67 - let theaters_info = new Map(); 67 + for(let i = 1; i <= 9; i++){
68 - let theaters_by_area = await elem.wait(until.elementsLocated(By.tagName('a'))); 68 + let region = await driver_theaters.wait(until.elementsLocated(By.css(selector.replace("{}", i))));
69 - theaters_by_area.forEach(theater => { 69 + area.push(region);
70 - const theater_name = theater.getAttribute("title").replace("CGV", "");
71 - const theater_code = theater.getAttribute("href").replaceAll("(.+(?<=theaterCode=))|(.+(?<=theatercode=))", "").substring(0,4);
72 - theaters_info.set(theater_name, theater_code);
73 - });
74 - cgv_theaters.push(theaters_info);
75 } 70 }
71 + let n = 0;
72 + for (const theaters_by_area of area) {
73 + let theaters_info_by_area = [];
74 + for (const theater of theaters_by_area){
75 + let theater_name = await theater.getAttribute('title');
76 + let theater_info = {
77 + "theater_name" : await theater.getAttribute('title'),
78 + "theater_code" : await theater.getAttribute('href')//.replace("(.+(?<=theaterCode=))|(.+(?<=theatercode=))", "").substring(0,4)
79 + };
80 + theater_info.theater_code = theater_info.theater_code.replace("(.+(?<=theaterCode=))|(.+(?<=theatercode=))", "").substring(0,4);
81 + theaters_info_by_area.push(theater_info);
82 + n++;
83 + //console.log(theater_info);
84 + }
85 + cgv_theaters.push(theaters_info_by_area);
86 + }
87 + console.log(n);
88 +
76 driver_theaters.close(); 89 driver_theaters.close();
77 }, 90 },
78 async () => { 91 async () => {
79 - const driver_movies = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless().build()); 92 + const driver_movies = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
80 driver_movies.get(url_movies); 93 driver_movies.get(url_movies);
81 //예매율 Top19까지의 영화의 정보를 가져옴. 94 //예매율 Top19까지의 영화의 정보를 가져옴.
82 - const chart = await driver_movies.wait(until.elementLocated(By.className("sect-movie-chart"))); 95 + let chart = await driver_movies.wait(until.elementLocated(By.className("sect-movie-chart")));
83 - const rank = await chart.wait(until.elementsLocated(By.css("strong.rank"))); 96 + const rank = chart.findElements(By.css("strong.rank"));
84 - const title = await chart.wait(until.elementsLocated(By.css("strong.title"))); 97 + const title = chart.findElements(By.css("strong.title"));
85 - const score = await chart.wait(until.elementsLocated(By.css("strong.percent"))); 98 + const score = chart.findElements(By.css("strong.percent"));
86 - const GoldenEgg = await chart.wait(until.elementsLocated(By.css("span.percent"))); 99 + const GoldenEgg = chart.findElements(By.css("span.percent"));
87 - const link = await chart.wait(until.elementsLocated(By.css("a.plink-reservation"))); 100 + const link = chart.findElements(By.css("a.plink-reservation"));
88 101
89 //영화 제목, 순위, 예매율, 영화 코드, 골든에그 지수를 가져와 CGVMovieInfo 객체 생성자에 파라미터로 넘겨주고, 인스턴스를 받아옴. 102 //영화 제목, 순위, 예매율, 영화 코드, 골든에그 지수를 가져와 CGVMovieInfo 객체 생성자에 파라미터로 넘겨주고, 인스턴스를 받아옴.
90 for (let i = 0; i < rank.length; i++) { 103 for (let i = 0; i < rank.length; i++) {
...@@ -95,5 +108,16 @@ async.waterfall([ ...@@ -95,5 +108,16 @@ async.waterfall([
95 const newMovie = new CGVMovieInfo(newTitle, newRank, newScore, GoldenEgg[i], newCode); 108 const newMovie = new CGVMovieInfo(newTitle, newRank, newScore, GoldenEgg[i], newCode);
96 cgv_movies.push(newMovie); 109 cgv_movies.push(newMovie);
97 } 110 }
111 + driver_movies.close();
98 } 112 }
99 ]); 113 ]);
114 +
115 +app.get('/cgv_theaters', (req, res) => {
116 + res.send(cgv_theaters[0]);
117 +});
118 +
119 +app.post('', (req, res) => {
120 +
121 +});
122 +
123 +app.listen(23023);
...\ No newline at end of file ...\ No newline at end of file
......