Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ShinSeungMin
/
Multiplex_Ticketing_Platform
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
임승현
2022-05-24 01:41:43 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9d512bb18be08583a859b00c0e5becff0c12198a
9d512bb1
1 parent
1a725f8a
Edit toEnable to Choose the Theater
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
18 deletions
WebCrawling/chromedriver
WebCrawling/src/CGVExample.java
WebCrawling/chromedriver
0 → 100755
View file @
9d512bb
This file is too large to display.
WebCrawling/src/CGVExample.java
View file @
9d512bb
...
...
@@ -8,6 +8,13 @@ import java.io.*;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.util.*
;
import
java.util.List
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
org.openqa.selenium.chrome.ChromeOptions
;
class
CGVMovieInfo
{
//CGV 영화 정보를 담는 class
private
String
title
;
//영화 제목
...
...
@@ -80,20 +87,58 @@ class CGVMovieInfo { //CGV 영화 정보를 담는 class
}
public
class
CGVExample
{
public
static
final
String
WEB_DRIVER_ID
=
"webdriver.chrome.driver"
;
//드라이버 ID
public
static
final
String
WEB_DRIVER_PATH
=
"WebCrawling/chromedriver"
;
//드라이버 경로
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
String
url_movies
=
"https://www.cgv.co.kr/movies/?lt=1&ft=1"
;
//끝의 쿼리 0은 개봉 전 영화도 포함하는 것. 예매율 순위 가져오기
String
url_theaters
=
"https://www.cgv.co.kr/theaters"
;
//영화관 정보 가져오
기
.
String
url_theaters
=
"https://www.cgv.co.kr/theaters"
;
//영화관 정보 가져오
는 링크
.
Document
doc_movies
,
doc_theaters
;
ArrayList
<
LinkedHashMap
<
String
,
Integer
>>
Theaters
=
new
ArrayList
<>();
//지역별 영화관 HashMap(Key: 영화관, value:영화관별 고유코드)으로 이루어진 Arraylist
ArrayList
<
LinkedHashMap
<
String
,
String
>>
theaters
=
new
ArrayList
<>();
//지역별 영화관 HashMap(Key: 영화관, value:영화관별 고유코드)으로 이루어진 Arraylist
ArrayList
<
CGVMovieInfo
>
Movies
=
new
ArrayList
<>();
//CGVMovieInfo 클래스의 인스턴스들을 원소로 가지는 Arraylist
try
{
//드라이버 설정
System
.
setProperty
(
WEB_DRIVER_ID
,
WEB_DRIVER_PATH
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
ChromeOptions
options
=
new
ChromeOptions
();
//크롬 설정을 담은 객체 생성
options
.
addArguments
(
"headless"
);
//브라우저가 눈에 보이지 않고 컴파일러 내부에서 작동됨.
WebDriver
driver
=
new
ChromeDriver
(
options
);
//위에서 설정한 옵션을 파라미터로 넘겨주고, 드라이버 객체 생성.
driver
.
get
(
url_theaters
);
//WebDriver 객체를 해당 URL로 이동시킨다.
//브라우저 이동시 생기는 로드시간을 기다린다.
//HTTP 응답속도 보다 자바의 컴파일 속도가 더 빠르기 때문에 임의적으로 1초를 대기한다.
try
{
Thread
.
sleep
(
1000
);}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();}
//영화관 및 영화관에 대응되는 영화관별 고유 코드 가져오기.
List
<
WebElement
>
area
=
driver
.
findElements
(
By
.
className
(
"area"
));
for
(
WebElement
elem
:
area
)
{
LinkedHashMap
<
String
,
String
>
theaters_info
=
new
LinkedHashMap
<>();
List
<
WebElement
>
theaters_by_area
=
elem
.
findElements
(
By
.
tagName
(
"a"
));
for
(
WebElement
theater
:
theaters_by_area
)
{
String
theater_name
=
theater
.
getAttribute
(
"title"
).
replace
(
"CGV"
,
""
);
String
theater_code
=
theater
.
getAttribute
(
"href"
).
replaceAll
(
"(.+(?<=theaterCode=))|(.+(?<=theatercode=))"
,
""
).
substring
(
0
,
4
);
theaters_info
.
put
(
theater_name
,
theater_code
);
}
theaters
.
add
(
theaters_info
);
}
try
{
doc_movies
=
Jsoup
.
connect
(
url_movies
).
get
();
doc_theaters
=
Jsoup
.
connect
(
url_theaters
).
get
();
driver
.
close
();
//드라이버 연결 해제
driver
.
quit
();
//프로세스 종료
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
.
getMessage
());
}
Document
doc_movies
;
try
{
doc_movies
=
Jsoup
.
connect
(
url_movies
).
get
();
//예매율 Top19까지의 영화의 정보를 가져옴.
Elements
elements1
=
doc_movies
.
select
(
"div.sect-movie-chart"
);
Iterator
<
Element
>
rank
=
elements1
.
select
(
"strong.rank"
).
iterator
();
...
...
@@ -102,10 +147,6 @@ public class CGVExample {
Iterator
<
Element
>
GoldenEgg
=
elements1
.
select
(
"span.percent"
).
iterator
();
Iterator
<
Element
>
link
=
elements1
.
select
(
"a.link-reservation"
).
iterator
();
//서울/경기/인천/강원/대전,충청/대구/부산,울산/경상/광주,전라,제주 - 광역 정보 가져오기
Elements
elements2
=
doc_theaters
.
getElementsByAttributeValue
(
"class"
,
"sect-city"
);
Iterator
<
Element
>
region
=
elements2
.
select
(
"li.on"
).
iterator
();
while
(
title
.
hasNext
()){
String
newTitle
=
title
.
next
().
text
();
int
newRank
=
Integer
.
parseInt
(
rank
.
next
().
text
().
replace
(
"No."
,
""
));
...
...
@@ -115,24 +156,32 @@ public class CGVExample {
CGVMovieInfo
newMovie
=
new
CGVMovieInfo
(
newTitle
,
newRank
,
newScore
,
GoldenEgg
.
next
().
text
(),
newCode
);
Movies
.
add
(
newMovie
);
}
while
(
region
.
hasNext
()){
System
.
out
.
println
(
region
.
next
().
text
());
}
}
catch
(
IOException
e
){
e
.
printStackTrace
();
}
for
(
CGVMovieInfo
elem
:
Movies
)
{
//
elem.printMovieInfo();
System
.
out
.
println
(
elem
.
getRank
()
+
" : "
+
elem
.
getTitle
());
elem
.
printMovieInfo
();
//
System.out.println(elem.getRank() + " : " + elem.getTitle());
}
//영화 이름(Integer 선택지), 영화관 지역 코드, 영화관 이름, 관람 일자 입력 시, (시간 선택 가능한) 예매 사이트로 이동.
System
.
out
.
print
(
"예매하고 싶은 영화의 순위를 입력하세요 : "
);
int
inputRank
=
scanner
.
nextInt
();
System
.
out
.
print
(
"지역 코드를 입력하세요 : "
);
int
regionCode
=
scanner
.
nextInt
();
System
.
out
.
print
(
"영화관명을 입력하세요 : "
);
String
theaterName
=
scanner
.
next
();
String
theaterCode
=
theaters
.
get
(
regionCode
).
get
(
theaterName
);
System
.
out
.
print
(
"관람 일자를 입력하세요 : "
);
int
date
=
scanner
.
nextInt
();
try
{
Desktop
.
getDesktop
().
browse
(
new
URI
(
Movies
.
get
(
inputRank
-
1
).
getLink
()));
String
otherFormat
=
String
.
format
(
"&THEATER_CD=%s&PLAY_YMD=%s"
,
theaterCode
,
date
);
Desktop
.
getDesktop
().
browse
(
new
URI
(
Movies
.
get
(
inputRank
-
1
).
getLink
()
+
otherFormat
));
}
catch
(
IndexOutOfBoundsException
|
URISyntaxException
|
IOException
e
){
System
.
out
.
println
(
e
.
getClass
());
...
...
Please
register
or
login
to post a comment