Showing
10 changed files
with
176 additions
and
0 deletions
WebCrawling/.idea/.gitignore
0 → 100644
WebCrawling/.idea/libraries/jsoup_1_15_1.xml
0 → 100644
WebCrawling/.idea/misc.xml
0 → 100644
| 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 |
WebCrawling/.idea/modules.xml
0 → 100644
| 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 |
WebCrawling/.idea/vcs.xml
0 → 100644
WebCrawling/WebCrawling.iml
0 → 100644
| 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 |
WebCrawling/jsoup-1.15.1.jar
0 → 100644
No preview for this file type
No preview for this file type
No preview for this file type
WebCrawling/src/CGVExample.java
0 → 100644
| 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 java.awt.*; | ||
| 7 | +import java.io.*; | ||
| 8 | +import java.net.URI; | ||
| 9 | +import java.net.URISyntaxException; | ||
| 10 | +import java.util.*; | ||
| 11 | + | ||
| 12 | +class CGVMovieInfo { //CGV 영화 정보를 담는 class | ||
| 13 | + private String title; //영화 제목 | ||
| 14 | + private int rank; //CGV 내 예매율 순위 | ||
| 15 | + private float score; //예매율 | ||
| 16 | + private String GoldenEgg; //골든에그 지수 | ||
| 17 | + private String movieCode; //CGV 고유 영화코드 - 예매 사이트 연결 시 사용 | ||
| 18 | + | ||
| 19 | + public CGVMovieInfo(String title, int rank, float score, String GoldenEgg, String movieCode) { | ||
| 20 | + this.title = title; | ||
| 21 | + this.rank = rank; | ||
| 22 | + this.score = score; | ||
| 23 | + this.GoldenEgg = GoldenEgg; | ||
| 24 | + this.movieCode = movieCode; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public String getTitle() { | ||
| 28 | + return title; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setTitle(String title) { | ||
| 32 | + this.title = title; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public int getRank() { | ||
| 36 | + return rank; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setRank(int rank) { | ||
| 40 | + this.rank = rank; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public float getScore() { | ||
| 44 | + return score; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public void setScore(float score) { | ||
| 48 | + this.score = score; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public String getGoldenEgg() { | ||
| 52 | + return GoldenEgg; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public void setGoldenEgg(String goldenEgg) { | ||
| 56 | + GoldenEgg = goldenEgg; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public String getMovieCode() { | ||
| 60 | + return movieCode; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void setMovieCode(String movieCode) { | ||
| 64 | + this.movieCode = movieCode; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public String getLink() { | ||
| 68 | + return String.format("https://www.cgv.co.kr/ticket/?MOVIE_CD=%s&MOVIE_CD_GROUP=%s", this.movieCode, this.movieCode); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void printMovieInfo(){ | ||
| 72 | + System.out.println("-------------------------------------------------------"); | ||
| 73 | + System.out.println(this.rank + " : " + this.title); | ||
| 74 | + System.out.println("예매율 : " + this.score + "%"); | ||
| 75 | + System.out.println("골든에그지수 : " + this.GoldenEgg); | ||
| 76 | + System.out.println("영화코드 : " + this.movieCode); | ||
| 77 | + System.out.println("-------------------------------------------------------"); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +public class CGVExample { | ||
| 83 | + public static void main(String[] args) { | ||
| 84 | + Scanner scanner = new Scanner(System.in); | ||
| 85 | + String url = "https://www.cgv.co.kr/movies/?lt=1&ft=1"; //끝의 쿼리 0은 개봉 전 영화도 포함하는 것. | ||
| 86 | + Document doc = null; | ||
| 87 | + ArrayList<CGVMovieInfo> Movies = new ArrayList<>(); | ||
| 88 | + try { | ||
| 89 | + doc = Jsoup.connect(url).get(); | ||
| 90 | + //Top 19 까지 | ||
| 91 | + Elements elements1 = doc.select("div.sect-movie-chart"); | ||
| 92 | + Iterator<Element> rank = elements1.select("strong.rank").iterator(); | ||
| 93 | + Iterator<Element> title = elements1.select("strong.title").iterator(); | ||
| 94 | + Iterator<Element> score = elements1.select("strong.percent").iterator(); | ||
| 95 | + Iterator<Element> GoldenEgg = elements1.select("span.percent").iterator(); | ||
| 96 | + Iterator<Element> link = elements1.select("a.link-reservation").iterator(); | ||
| 97 | + | ||
| 98 | + //Top 19 이후 | ||
| 99 | + //Elements elements2 = doc.select("div.sect-movie-chart"); | ||
| 100 | + | ||
| 101 | + while(title.hasNext()){ | ||
| 102 | + String newTitle = title.next().text(); | ||
| 103 | + int newRank = Integer.parseInt(rank.next().text().replace("No.","")); | ||
| 104 | + float newScore = Float.parseFloat(score.next().text().replace("예매율", "").replace("%", "")); | ||
| 105 | + String newCode = link.next().attr("href").replaceAll("[^0-9]", "").substring(0,8); | ||
| 106 | + | ||
| 107 | + CGVMovieInfo newMovie = new CGVMovieInfo(newTitle, newRank, newScore, GoldenEgg.next().text(), newCode); | ||
| 108 | + Movies.add(newMovie); | ||
| 109 | + } | ||
| 110 | + }catch(IOException e){ | ||
| 111 | + e.printStackTrace(); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + for (CGVMovieInfo elem : Movies) { | ||
| 115 | + System.out.println(elem.getRank() + " : " + elem.getTitle()); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + System.out.print("관람하고 싶은 영화의 순위를 입력하세요 : "); | ||
| 119 | + int inputRank = scanner.nextInt(); | ||
| 120 | + try{ | ||
| 121 | + Desktop.getDesktop().browse(new URI(Movies.get(inputRank - 1).getLink())); | ||
| 122 | + } | ||
| 123 | + catch(IndexOutOfBoundsException | URISyntaxException | IOException e){ | ||
| 124 | + System.out.println(e.getClass()); | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | +} |
-
Please register or login to post a comment