임승현

Crawl Infomation of CGV Movies

# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<component name="libraryTable">
<library name="jsoup-1.15.1">
<CLASSES>
<root url="jar://$PROJECT_DIR$/jsoup-1.15.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/WebCrawling.iml" filepath="$PROJECT_DIR$/WebCrawling.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jsoup-1.15.1" level="project" />
</component>
</module>
\ No newline at end of file
No preview for this file type
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.awt.*;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
class CGVMovieInfo { //CGV 영화 정보를 담는 class
private String title; //영화 제목
private int rank; //CGV 내 예매율 순위
private float score; //예매율
private String GoldenEgg; //골든에그 지수
private String movieCode; //CGV 고유 영화코드 - 예매 사이트 연결 시 사용
public CGVMovieInfo(String title, int rank, float score, String GoldenEgg, String movieCode) {
this.title = title;
this.rank = rank;
this.score = score;
this.GoldenEgg = GoldenEgg;
this.movieCode = movieCode;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
public String getGoldenEgg() {
return GoldenEgg;
}
public void setGoldenEgg(String goldenEgg) {
GoldenEgg = goldenEgg;
}
public String getMovieCode() {
return movieCode;
}
public void setMovieCode(String movieCode) {
this.movieCode = movieCode;
}
public String getLink() {
return String.format("https://www.cgv.co.kr/ticket/?MOVIE_CD=%s&MOVIE_CD_GROUP=%s", this.movieCode, this.movieCode);
}
public void printMovieInfo(){
System.out.println("-------------------------------------------------------");
System.out.println(this.rank + " : " + this.title);
System.out.println("예매율 : " + this.score + "%");
System.out.println("골든에그지수 : " + this.GoldenEgg);
System.out.println("영화코드 : " + this.movieCode);
System.out.println("-------------------------------------------------------");
}
}
public class CGVExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String url = "https://www.cgv.co.kr/movies/?lt=1&ft=1"; //끝의 쿼리 0은 개봉 전 영화도 포함하는 것.
Document doc = null;
ArrayList<CGVMovieInfo> Movies = new ArrayList<>();
try {
doc = Jsoup.connect(url).get();
//Top 19 까지
Elements elements1 = doc.select("div.sect-movie-chart");
Iterator<Element> rank = elements1.select("strong.rank").iterator();
Iterator<Element> title = elements1.select("strong.title").iterator();
Iterator<Element> score = elements1.select("strong.percent").iterator();
Iterator<Element> GoldenEgg = elements1.select("span.percent").iterator();
Iterator<Element> link = elements1.select("a.link-reservation").iterator();
//Top 19 이후
//Elements elements2 = doc.select("div.sect-movie-chart");
while(title.hasNext()){
String newTitle = title.next().text();
int newRank = Integer.parseInt(rank.next().text().replace("No.",""));
float newScore = Float.parseFloat(score.next().text().replace("예매율", "").replace("%", ""));
String newCode = link.next().attr("href").replaceAll("[^0-9]", "").substring(0,8);
CGVMovieInfo newMovie = new CGVMovieInfo(newTitle, newRank, newScore, GoldenEgg.next().text(), newCode);
Movies.add(newMovie);
}
}catch(IOException e){
e.printStackTrace();
}
for (CGVMovieInfo elem : Movies) {
System.out.println(elem.getRank() + " : " + elem.getTitle());
}
System.out.print("관람하고 싶은 영화의 순위를 입력하세요 : ");
int inputRank = scanner.nextInt();
try{
Desktop.getDesktop().browse(new URI(Movies.get(inputRank - 1).getLink()));
}
catch(IndexOutOfBoundsException | URISyntaxException | IOException e){
System.out.println(e.getClass());
}
}
}