이혜인

Remove not needed large file

1 -# Default ignored files
2 -/shelf/
3 -/workspace.xml
4 -# Editor-based HTTP Client requests
5 -/httpRequests/
6 -# Datasource local storage ignored files
7 -/dataSources/
8 -/dataSources.local.xml
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<project version="4">
3 - <component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
4 - <output url="file://$PROJECT_DIR$/out" />
5 - </component>
6 -</project>
...\ No newline at end of file ...\ No newline at end of file
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<project version="4">
3 - <component name="ProjectModuleManager">
4 - <modules>
5 - <module fileurl="file://$PROJECT_DIR$/WebCrawling.iml" filepath="$PROJECT_DIR$/WebCrawling.iml" />
6 - </modules>
7 - </component>
8 -</project>
...\ No newline at end of file ...\ No newline at end of file
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<project version="4">
3 - <component name="VcsDirectoryMappings">
4 - <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5 - </component>
6 -</project>
...\ No newline at end of file ...\ No newline at end of file
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<module type="JAVA_MODULE" version="4">
3 - <component name="NewModuleRootManager" inherit-compiler-output="true">
4 - <exclude-output />
5 - <content url="file://$MODULE_DIR$">
6 - <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7 - </content>
8 - <orderEntry type="inheritedJdk" />
9 - <orderEntry type="sourceFolder" forTests="false" />
10 - <orderEntry type="library" name="jsoup-1.15.1" level="project" />
11 - </component>
12 -</module>
...\ No newline at end of file ...\ No newline at end of file
This file is too large to display.
No preview for this file type
1 -import org.jsoup.Jsoup;
2 -import org.jsoup.nodes.Document;
3 -import org.jsoup.nodes.Element;
4 -import org.jsoup.select.Elements;
5 -
6 -import org.openqa.selenium.By;
7 -import org.openqa.selenium.WebDriver;
8 -import org.openqa.selenium.WebElement;
9 -import org.openqa.selenium.chrome.ChromeDriver;
10 -import org.openqa.selenium.chrome.ChromeOptions;
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
20 - private String title; //영화 제목
21 - private int rank; //CGV 내 예매율 순위
22 - private float score; //예매율
23 - private String GoldenEgg; //골든에그 지수
24 - private String movieCode; //CGV 고유 영화코드 - 예매 사이트 연결 시 사용
25 -
26 - public CGVMovieInfo(String title, int rank, float score, String GoldenEgg, String movieCode) {
27 - this.title = title;
28 - this.rank = rank;
29 - this.score = score;
30 - this.GoldenEgg = GoldenEgg;
31 - this.movieCode = movieCode;
32 - }
33 -
34 - public String getTitle() {
35 - return title;
36 - }
37 -
38 - public void setTitle(String title) {
39 - this.title = title;
40 - }
41 -
42 - public int getRank() {
43 - return rank;
44 - }
45 -
46 - public void setRank(int rank) {
47 - this.rank = rank;
48 - }
49 -
50 - public float getScore() {
51 - return score;
52 - }
53 -
54 - public void setScore(float score) {
55 - this.score = score;
56 - }
57 -
58 - public String getGoldenEgg() {
59 - return GoldenEgg;
60 - }
61 -
62 - public void setGoldenEgg(String goldenEgg) {
63 - GoldenEgg = goldenEgg;
64 - }
65 -
66 - public String getMovieCode() {
67 - return movieCode;
68 - }
69 -
70 - public void setMovieCode(String movieCode) {
71 - this.movieCode = movieCode;
72 - }
73 -
74 - public String getLink() {
75 - return String.format("https://www.cgv.co.kr/ticket/?MOVIE_CD=%s&MOVIE_CD_GROUP=%s", this.movieCode, this.movieCode);
76 - }
77 -
78 - public void printMovieInfo(){
79 - System.out.println("-------------------------------------------------------");
80 - System.out.println(this.rank + " : " + this.title);
81 - System.out.println("예매율 : " + this.score + "%");
82 - System.out.println("골든에그지수 : " + this.GoldenEgg);
83 - System.out.println("영화코드 : " + this.movieCode);
84 - System.out.println("-------------------------------------------------------");
85 - }
86 -
87 -}
88 -
89 -public class CGVExample {
90 -
91 - public static final String WEB_DRIVER_ID = "webdriver.chrome.driver"; //드라이버 ID
92 - public static final String WEB_DRIVER_PATH = "WebCrawling/chromedriver"; //드라이버 경로
93 -
94 - public static void main(String[] args) {
95 -
96 - Scanner scanner = new Scanner(System.in);
97 - String url_movies = "https://www.cgv.co.kr/movies/?lt=1&ft=1"; //끝의 쿼리 0은 개봉 전 영화도 포함하는 것. 예매율 순위 가져오기
98 - String url_theaters = "https://www.cgv.co.kr/theaters"; //영화관 정보 가져오는 링크.
99 - String url_ticketing = "https://www.cgv.co.kr/ticket/"; //상영중인 영화 정보 가져오는 링크.
100 -
101 - ArrayList<LinkedHashMap<String, String>> theaters = new ArrayList<>(); //지역별 영화관 HashMap(Key: 영화관, value:영화관별 고유코드)으로 이루어진 Arraylist
102 - ArrayList<CGVMovieInfo> Movies = new ArrayList<>(); //CGVMovieInfo 클래스의 인스턴스들을 원소로 가지는 Arraylist
103 -
104 - // 여기부터 영화관 및 영화관별 고유코드 가져오는 부분.
105 - try{ //드라이버 설정
106 - System.setProperty(WEB_DRIVER_ID,WEB_DRIVER_PATH);
107 - }catch (Exception e){
108 - e.printStackTrace();
109 - }
110 -
111 - ChromeOptions options = new ChromeOptions(); //크롬 설정을 담은 객체 생성
112 - options.addArguments("headless"); //브라우저가 눈에 보이지 않고 컴파일러 내부에서 작동됨.
113 -
114 - WebDriver driver_theaters = new ChromeDriver(options); //위에서 설정한 옵션을 파라미터로 넘겨주고, 드라이버 객체 생성.
115 - driver_theaters.get(url_theaters); //WebDriver 객체를 해당 URL로 이동시킨다.
116 -
117 - //브라우저 이동시 생기는 로드시간을 기다린다.
118 - //HTTP 응답속도 보다 자바의 컴파일 속도가 더 빠르기 때문에 임의적으로 1초를 대기한다.
119 - try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}
120 -
121 - //영화관 및 영화관에 대응되는 영화관별 고유 코드 가져오기.
122 - List<WebElement> area = driver_theaters.findElements(By.className("area"));
123 - for (WebElement elem : area) {
124 - LinkedHashMap<String, String> theaters_info = new LinkedHashMap<>();
125 - List<WebElement> theaters_by_area = elem.findElements(By.tagName("a"));
126 - for (WebElement theater : theaters_by_area) {
127 - String theater_name = theater.getAttribute("title").replace("CGV", "");
128 - String theater_code = theater.getAttribute("href").replaceAll("(.+(?<=theaterCode=))|(.+(?<=theatercode=))", "").substring(0,4);
129 - theaters_info.put(theater_name, theater_code);
130 - }
131 - theaters.add(theaters_info);
132 - }
133 -
134 - try {
135 - driver_theaters.close(); //드라이버 연결 해제
136 - driver_theaters.quit(); //프로세스 종료
137 - } catch (Exception e) {
138 - throw new RuntimeException(e.getMessage());
139 - }
140 -
141 - //여기부터 예매율 순위 가져오는 부분
142 - Document doc_movies;
143 - try {
144 - doc_movies = Jsoup.connect(url_movies).get();
145 - //예매율 Top19까지의 영화의 정보를 가져옴.
146 - Elements elements1 = doc_movies.select("div.sect-movie-chart");
147 - Iterator<Element> rank = elements1.select("strong.rank").iterator();
148 - Iterator<Element> title = elements1.select("strong.title").iterator();
149 - Iterator<Element> score = elements1.select("strong.percent").iterator();
150 - Iterator<Element> GoldenEgg = elements1.select("span.percent").iterator();
151 - Iterator<Element> link = elements1.select("a.link-reservation").iterator();
152 -
153 - //영화 제목, 순위, 예매율, 영화 코드, 골든에그 지수를 가져와 CGVMovieInfo 객체 생성자에 파라미터로 넘겨주고, 인스턴스를 받아옴.
154 - while(title.hasNext()){
155 - String newTitle = title.next().text();
156 - int newRank = Integer.parseInt(rank.next().text().replace("No.",""));
157 - float newScore = Float.parseFloat(score.next().text().replace("예매율", "").replace("%", ""));
158 - String newCode = link.next().attr("href").replaceAll("[^0-9]", "").substring(0,8);
159 -
160 - CGVMovieInfo newMovie = new CGVMovieInfo(newTitle, newRank, newScore, GoldenEgg.next().text(), newCode);
161 - Movies.add(newMovie);
162 - }
163 - }catch(IOException e){
164 - e.printStackTrace();
165 - }
166 -
167 - for (CGVMovieInfo elem : Movies) {
168 - //elem.printMovieInfo();
169 - System.out.println(elem.getRank() + " : " + elem.getTitle());
170 - }
171 -
172 - //영화 이름(Integer 선택지), 영화관 지역 코드, 영화관 이름, 관람 일자 입력 시, (시간 선택 가능한) 예매 사이트로 이동.
173 - System.out.print("예매하고 싶은 영화의 순위를 입력하세요 : ");
174 - int inputRank = scanner.nextInt();
175 -
176 - System.out.print("지역 코드를 입력하세요 : ");
177 - int regionCode = scanner.nextInt();
178 -
179 - System.out.print("영화관명을 입력하세요 : ");
180 - String theaterName = scanner.next();
181 - String theaterCode = theaters.get(regionCode).get(theaterName);
182 -
183 - System.out.print("관람 일자를 입력하세요 : ");
184 - int date = scanner.nextInt();
185 -
186 - String otherFormat = String.format("THEATER_CD=%s&PLAY_YMD=%s", theaterCode, date);
187 - url_ticketing += ("?" + otherFormat);
188 -
189 - //예매 가능한 영화 리스트를 얻기 위해 빠른 예매 사이트로 이동.
190 - WebDriver driver_ticketing = new ChromeDriver();
191 - driver_ticketing.get(url_ticketing);
192 - try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}
193 -
194 - //Frame 전환
195 - WebElement selecting_area = driver_ticketing.switchTo().frame("ticket_iframe").findElement(By.className("theater-area-list"));
196 - List<WebElement> selected_areas_list = selecting_area.findElements(By.cssSelector("ul > li > a > span.name"));
197 -
198 - //지역 코드에 맞게 list element click
199 - selected_areas_list.get(regionCode).click();
200 - try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}
201 -
202 - //선택한 지역에 대응되는 영화관 정보 가져오기
203 - WebElement selecting_theaters = selecting_area.findElement(By.cssSelector("ul > li.selected > div > ul"));
204 - List<WebElement> selected_theaters_list = selecting_theaters.findElements(By.tagName("li"));
205 -
206 - //프로그램 내부에서 가지고 있는 영화관코드와 웹에서 받아온 영화관코드가 일치하는 경우, selected_theaters_list element 클릭
207 - for(WebElement theater_element : selected_theaters_list) {
208 - if(theater_element.getAttribute("theater_cd").equals(theaterCode)){
209 - theater_element.click();
210 - try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}
211 - break;
212 - }
213 - }
214 -
215 - //선택한 영화관에서, 선택한 일자에 상영하는 영화 목록 들고오기
216 - WebElement selecting_movies = driver_ticketing.findElement(By.className("movie-select"));
217 - List<WebElement> selected_movies_list = selecting_movies.findElements(By.cssSelector("#movie_list > ul > li"));
218 - LinkedHashMap<String, String> accessible_movies = new LinkedHashMap<>();
219 -
220 - //선택불가를 제외한 영화 제목 출력
221 - for(WebElement movie_element : selected_movies_list){
222 - String movie_enabled = movie_element.getAttribute("class");
223 - if(movie_enabled.endsWith("dimmed"))
224 - break;
225 - else{
226 - String title = movie_element.findElement(By.cssSelector("span.text")).getText();
227 - String code = movie_element.getAttribute("movie_cd_group");
228 - accessible_movies.put(title, code);
229 - System.out.println(title + " : " + code);
230 - }
231 - }
232 -
233 - try{
234 - driver_ticketing.close(); //드라이버 연결 해제
235 - driver_ticketing.quit(); //프로세스 종료
236 - } catch (Exception e) {
237 - throw new RuntimeException(e.getMessage());
238 - }
239 -
240 - try{
241 - Desktop.getDesktop().browse(new URI(Movies.get(inputRank - 1).getLink() + "&" + otherFormat));
242 - }
243 - catch(IndexOutOfBoundsException | URISyntaxException | IOException e){
244 - System.out.println(e.getClass());
245 - }
246 - }
247 -}
1 -require('chromedriver');
2 -const request = require('request');
3 -const cheerio = require('cheerio');
4 -const puppeteer = require('puppeteer');
5 -
6 -const async = require('async');
7 -let express = require('express');
8 -let app = express();
9 -let bodyParser = require('body-parser');
10 -const { timeout } = require('async');
11 -
12 -const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기
13 -const webdriver = require('selenium-webdriver');
14 -const chrome = require('selenium-webdriver/chrome');
15 -const { delayed } = require('selenium-webdriver/lib/promise');
16 -const By = webdriver.By;
17 -
18 -app.use(bodyParser.urlencoded({ extended: false }));
19 -app.use(bodyParser.json());
20 -
21 -const url_movies = "https://www.cgv.co.kr/movies/?lt=1&ft=0"; //끝의 쿼리 0은 개봉 전 영화도 포함하는 것. 예매율 순위 가져오기
22 -const url_theaters = "https://www.cgv.co.kr/theaters"; //영화관 정보 가져오는 링크.
23 -const url_ticketing = "https://www.cgv.co.kr/ticket/"; //상영중인 영화 정보 가져오는 링크.
24 -
25 -let cgv_theaters = []; //영화관과 영화관 고유 코드를 담는 배열
26 -let cgv_movies = []; //예매율 상위 19위까지의 영화 정보(CGVMovieInfo Class의 인스턴스)들을 담는 배열.
27 -let cgv_accessible_movies = []; //선택한 일자, 영화관에서 예매할 수 있는 영화 이름과 영화 고유 코드를 담는 배열.
28 -
29 -class CGVMovieInfo {
30 - constructor(title, rank, score, GoldenEgg, movieCode){
31 - this.title = title;
32 - this.rank = rank;
33 - this.score = score;
34 - this.GoldenEgg = GoldenEgg;
35 - this.movieCode = movieCode;
36 - }
37 -
38 - getTitle() { return this.title; }
39 - setTitle(title) { this.title = title; }
40 - getRank() { return this.rank; }
41 - setRank(rank) { this.rank = rank; }
42 - getScore() { return this.score; }
43 - setScore(score) { this.score = score; }
44 - getGoldenEgg() { return this.GoldenEgg; }
45 - setGoldenEgg(GoldenEgg) { this.GoldenEgg = GoldenEgg; }
46 - getMovieCode() { return this.movieCode; }
47 - setMovieCode(movieCode) { this.movieCode = movieCode; }
48 -
49 - printMovieInfo(){
50 - return {
51 - 'rank': this.rank + " : " + this.title,
52 - 'score': "예매율 : " + this.score + "%",
53 - 'goldenEgg': "골든에그지수 : " + this.GoldenEgg,
54 - 'movieCode': "영화코드 : " + this.movieCode
55 - };
56 - }
57 -
58 -}
59 -
60 -async.waterfall([
61 - async () => {
62 - //크롬 설정을 담은 객체 생성
63 - const driver_theaters = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
64 - driver_theaters.get(url_theaters);
65 - //영화관 및 영화관에 대응되는 영화관별 고유 코드 가져오기.
66 - let selector = '#contents > div.sect-common > div > div.sect-city > ul > li:nth-child({}) > div > ul > li > a';
67 - let area = [];
68 - for(let i = 1; i <= 9; i++){
69 - let region = await driver_theaters.wait(until.elementsLocated(By.css(selector.replace("{}", i))));
70 - area.push(region);
71 - }
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_info = {
76 - "theater_name" : await theater.getAttribute('title'),
77 - "theater_code" : await theater.getAttribute('href')
78 - };
79 - theater_info.theater_name = theater_info.theater_name.replace("CGV", "")
80 - theater_info.theater_code = theater_info.theater_code.replace(/(.+(?<=theaterCode=))|(.+(?<=theatercode=))/, "").substring(0,4);
81 - theaters_info_by_area.push(theater_info);
82 - }
83 - cgv_theaters.push(theaters_info_by_area);
84 - }
85 - driver_theaters.close();
86 - },
87 - async () => {
88 - const driver_movies = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
89 - driver_movies.get(url_movies);
90 - //예매율 Top19까지의 영화의 정보를 가져옴.
91 -
92 - const rank = await driver_movies.wait(until.elementsLocated(By.css("strong.rank")));
93 - const title = await driver_movies.wait(until.elementsLocated(By.css("strong.title")));
94 - const score = await driver_movies.wait(until.elementsLocated(By.css("strong.percent")));
95 - const GoldenEgg = await driver_movies.wait(until.elementsLocated(By.css("span.percent")));
96 - const link = await driver_movies.wait(until.elementsLocated(By.css("a.link-reservation")));
97 -
98 - //영화 제목, 순위, 예매율, 영화 코드, 골든에그 지수를 가져와 CGVMovieInfo 객체 생성자에 파라미터로 넘겨주고, 인스턴스를 받아옴.
99 - for (let i = 0; i < rank.length; i++) {
100 - const newTitle = await title[i].getText();
101 - const newRank = await rank[i].getText();
102 - const newScore = await score[i].getText();
103 - const newCode = await link[i].getAttribute("href");
104 - const newMovie = new CGVMovieInfo(newTitle, parseInt(newRank.replace("No.", "")), newScore.replace("예매율", "").replace("%", ""), await GoldenEgg[i].getText(), newCode.replace(/[^0-9]/g, "").substring(0,8));
105 - cgv_movies.push(newMovie);
106 - }
107 - driver_movies.close();
108 - }
109 -])
110 -
111 -app.get('/cgv_theaters', (req, res) => {
112 - res.send(cgv_theaters[0]);
113 -});
114 -
115 -app.post('/ticketing', async (req, res, next) => {
116 - //영화관 이름과 날짜를 가져옴.
117 - const theaterName = req.body.theaterName;
118 - const date = req.body.date;
119 - const LocateQuery = "?PLAY_YMD={}".replace("{}", date);
120 -
121 - //입력된 영화관에 맞는 지역 코드와 영화관 고유코드 찾기
122 - let regionCode = 0, theaterCode = "";
123 - for(let i = 0; i < 9; i++){
124 - for(const elem of cgv_theaters[i]){
125 - if(elem.theater_name == theaterName){
126 - regionCode = i;
127 - theaterCode = elem.theater_code;
128 - break;
129 - }
130 - }
131 - }
132 -
133 - //예매 가능한 영화 리스트를 얻기 위해 빠른 예매 사이트로 이동.
134 - const driver_ticketing = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options()).build();
135 - driver_ticketing.get(url_ticketing + LocateQuery);
136 - driver_ticketing.switchTo().frame("ticket_iframe"); //Frame 전환
137 -
138 - //지역 코드에 맞게 list element click
139 - const selected_areas_list = await driver_ticketing.wait(until.elementsLocated(By.css("#theater_area_list > ul > li > a > span.name")));
140 - await selected_areas_list[regionCode].click();
141 - driver_ticketing.sleep(1000);
142 -
143 - //선택한 지역에 대응되는 영화관 정보 가져오기
144 - const selected_theaters_list = await driver_ticketing.wait(until.elementsLocated(By.css("#theater_area_list > ul > li.selected > div > ul > li")));
145 -
146 - //프로그램 내부에서 가지고 있는 영화관코드와 웹에서 받아온 영화관코드가 일치하는 경우, selected_theaters_list element 클릭
147 - for (const theater_element of selected_theaters_list){
148 - if(await theater_element.getAttribute("theater_cd") == theaterCode){
149 - await theater_element.click();
150 - driver_ticketing.sleep(1000);
151 - break;
152 - }
153 - }
154 -
155 - //선택한 영화관에서, 선택한 일자에 상영하는 영화 목록 들고오기
156 - const selected_movies_list = await driver_ticketing.wait(until.elementsLocated(By.css("#movie_list > ul > li > a > span.text")));
157 - const codes_of_selected_movies = await driver_ticketing.wait(until.elementsLocated(By.css("#movie_list > ul > li")));
158 -
159 - //선택불가를 제외한 영화 제목 및 영화 코드 가져오기.
160 - for(let i = 0; i < selected_movies_list.length; i++){
161 - const movie_enabled = await codes_of_selected_movies[i].getAttribute("class")
162 - if(movie_enabled.endsWith("dimmed"))
163 - break;
164 - const accessible_movie = {
165 - "movie_title": await selected_movies_list[i].getText(),
166 - "movie_code" : await codes_of_selected_movies[i].getAttribute("movie_cd_group")
167 - }
168 - cgv_accessible_movies.push(accessible_movie);
169 - }
170 - driver_ticketing.close();
171 -
172 - res.send(cgv_accessible_movies);
173 -});
174 -
175 -app.listen(23023);
...\ No newline at end of file ...\ No newline at end of file
1 -{
2 - "name": "test01",
3 - "version": "1.0.0",
4 - "description": "",
5 - "main": "index.js",
6 - "scripts": {
7 - "test": "echo \"Error: no test specified\" && exit 1"
8 - },
9 - "author": "",
10 - "license": "ISC",
11 - "dependencies": {
12 - "async": "^3.2.3",
13 - "body-parser": "^1.20.0",
14 - "cheerio": "^1.0.0-rc.11",
15 - "express": "^4.18.1",
16 - "puppeteer": "^14.1.1",
17 - "selenium-webdriver": "^4.1.2"
18 - }
19 -}