임승현

Edit for Crawling CGV Theaters

...@@ -82,21 +82,29 @@ class CGVMovieInfo { //CGV 영화 정보를 담는 class ...@@ -82,21 +82,29 @@ class CGVMovieInfo { //CGV 영화 정보를 담는 class
82 public class CGVExample { 82 public class CGVExample {
83 public static void main(String[] args) { 83 public static void main(String[] args) {
84 Scanner scanner = new Scanner(System.in); 84 Scanner scanner = new Scanner(System.in);
85 - String url = "https://www.cgv.co.kr/movies/?lt=1&ft=1"; //끝의 쿼리 0은 개봉 전 영화도 포함하는 것. 85 + String url_movies = "https://www.cgv.co.kr/movies/?lt=1&ft=1"; //끝의 쿼리 0은 개봉 전 영화도 포함하는 것. 예매율 순위 가져오기
86 - Document doc; 86 + String url_theaters = "https://www.cgv.co.kr/theaters"; //영화관 정보 가져오기.
87 - ArrayList<CGVMovieInfo> Movies = new ArrayList<>(); 87 +
88 + Document doc_movies, doc_theaters;
89 +
90 + ArrayList<LinkedHashMap<String, Integer>> Theaters = new ArrayList<>(); //지역별 영화관 HashMap(Key: 영화관, value:영화관별 고유코드)으로 이루어진 Arraylist
91 + ArrayList<CGVMovieInfo> Movies = new ArrayList<>(); //CGVMovieInfo 클래스의 인스턴스들을 원소로 가지는 Arraylist
92 +
88 try { 93 try {
89 - doc = Jsoup.connect(url).get(); 94 + doc_movies = Jsoup.connect(url_movies).get();
90 - //Top 19 까지 95 + doc_theaters = Jsoup.connect(url_theaters).get();
91 - Elements elements1 = doc.select("div.sect-movie-chart"); 96 +
97 + //예매율 Top19까지의 영화의 정보를 가져옴.
98 + Elements elements1 = doc_movies.select("div.sect-movie-chart");
92 Iterator<Element> rank = elements1.select("strong.rank").iterator(); 99 Iterator<Element> rank = elements1.select("strong.rank").iterator();
93 Iterator<Element> title = elements1.select("strong.title").iterator(); 100 Iterator<Element> title = elements1.select("strong.title").iterator();
94 Iterator<Element> score = elements1.select("strong.percent").iterator(); 101 Iterator<Element> score = elements1.select("strong.percent").iterator();
95 Iterator<Element> GoldenEgg = elements1.select("span.percent").iterator(); 102 Iterator<Element> GoldenEgg = elements1.select("span.percent").iterator();
96 Iterator<Element> link = elements1.select("a.link-reservation").iterator(); 103 Iterator<Element> link = elements1.select("a.link-reservation").iterator();
97 104
98 - //Top 19 이후 105 + //서울/경기/인천/강원/대전,충청/대구/부산,울산/경상/광주,전라,제주 - 광역 정보 가져오기
99 - //Elements elements2 = doc.select("div.sect-movie-chart"); 106 + Elements elements2 = doc_theaters.getElementsByAttributeValue("class", "sect-city");
107 + Iterator<Element> region = elements2.select("li.on").iterator();
100 108
101 while(title.hasNext()){ 109 while(title.hasNext()){
102 String newTitle = title.next().text(); 110 String newTitle = title.next().text();
...@@ -107,13 +115,18 @@ public class CGVExample { ...@@ -107,13 +115,18 @@ public class CGVExample {
107 CGVMovieInfo newMovie = new CGVMovieInfo(newTitle, newRank, newScore, GoldenEgg.next().text(), newCode); 115 CGVMovieInfo newMovie = new CGVMovieInfo(newTitle, newRank, newScore, GoldenEgg.next().text(), newCode);
108 Movies.add(newMovie); 116 Movies.add(newMovie);
109 } 117 }
118 +
119 + while(region.hasNext()){
120 + System.out.println(region.next().text());
121 + }
122 +
110 }catch(IOException e){ 123 }catch(IOException e){
111 e.printStackTrace(); 124 e.printStackTrace();
112 } 125 }
113 126
114 for (CGVMovieInfo elem : Movies) { 127 for (CGVMovieInfo elem : Movies) {
115 - elem.printMovieInfo(); 128 + //elem.printMovieInfo();
116 - //System.out.println(elem.getRank() + " : " + elem.getTitle()); 129 + System.out.println(elem.getRank() + " : " + elem.getTitle());
117 } 130 }
118 131
119 System.out.print("예매하고 싶은 영화의 순위를 입력하세요 : "); 132 System.out.print("예매하고 싶은 영화의 순위를 입력하세요 : ");
......