Showing
1 changed file
with
67 additions
and
15 deletions
... | @@ -8,8 +8,15 @@ var By = webdriver.By; | ... | @@ -8,8 +8,15 @@ var By = webdriver.By; |
8 | const chrome = require('selenium-webdriver/chrome');//크롬 사용시 | 8 | const chrome = require('selenium-webdriver/chrome');//크롬 사용시 |
9 | 9 | ||
10 | const async = require('async') | 10 | const async = require('async') |
11 | +let express = require('express'); | ||
12 | +let app = express(); | ||
13 | +let bodyParser = require('body-parser'); | ||
14 | +const { timeout } = require('async'); | ||
15 | +app.use(bodyParser.urlencoded({ extended: false })); | ||
16 | +app.use(bodyParser.json()); | ||
11 | 17 | ||
12 | -let booking_url = "https://megabox.co.kr/booking"; | 18 | + |
19 | +const booking_url = "https://megabox.co.kr/booking"; | ||
13 | const rate_url = "https://www.megabox.co.kr/movie"; | 20 | const rate_url = "https://www.megabox.co.kr/movie"; |
14 | 21 | ||
15 | let r =0; | 22 | let r =0; |
... | @@ -17,10 +24,10 @@ let movie_data = []; | ... | @@ -17,10 +24,10 @@ let movie_data = []; |
17 | let location_data = []; | 24 | let location_data = []; |
18 | let index = 0; | 25 | let index = 0; |
19 | 26 | ||
20 | -async.waterfall([ | ||
21 | - async () => { | ||
22 | 27 | ||
23 | - const driver = new webdriver.Builder().forBrowser('chrome').build();//.setChromeOptions(new chrome.Options().headless()) | 28 | +async.waterfall([//for 동기적 처리 |
29 | + async () => { | ||
30 | + const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();// | ||
24 | driver.get(booking_url); | 31 | driver.get(booking_url); |
25 | driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 | 32 | driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 |
26 | 33 | ||
... | @@ -34,12 +41,15 @@ async.waterfall([ | ... | @@ -34,12 +41,15 @@ async.waterfall([ |
34 | const location_list = [seoul, Gyeonggi, Incheon, DCS, BDG, GJ, Gangwon]// | 41 | const location_list = [seoul, Gyeonggi, Incheon, DCS, BDG, GJ, Gangwon]// |
35 | for(let i = 0; i < location_list.length; i++){ | 42 | for(let i = 0; i < location_list.length; i++){ |
36 | for (item of location_list[i]) { | 43 | for (item of location_list[i]) { |
37 | - let location_name = await item.getAttribute("brch-nm"); | 44 | + location_data[index++] = { |
38 | - let location_num = await item.getAttribute("brch-no"); | 45 | + 'LocationName':await item.getAttribute("brch-nm"), |
39 | - let obj = {}; | 46 | + 'LocationNUm' : await item.getAttribute("brch-no") |
40 | - obj[location_name]= location_num | 47 | + } |
41 | - console.log(obj) | 48 | + // let location_name = await item.getAttribute("brch-nm"); |
42 | - location_data[index++] = obj; | 49 | + // let location_num = await item.getAttribute("brch-no"); |
50 | + // let obj = {}; | ||
51 | + // obj[location_name]= location_num | ||
52 | + // location_data[index++] = obj; | ||
43 | 53 | ||
44 | } | 54 | } |
45 | } | 55 | } |
... | @@ -52,7 +62,6 @@ async.waterfall([ | ... | @@ -52,7 +62,6 @@ async.waterfall([ |
52 | 'rank' : r, | 62 | 'rank' : r, |
53 | 'title' : await item.getAttribute("movie-nm"), | 63 | 'title' : await item.getAttribute("movie-nm"), |
54 | 'movie_num':await item.getAttribute("movie-no"), | 64 | 'movie_num':await item.getAttribute("movie-no"), |
55 | - 'running':await item.getAttribute("form-at"), | ||
56 | } | 65 | } |
57 | } | 66 | } |
58 | 67 | ||
... | @@ -81,13 +90,56 @@ async.waterfall([ | ... | @@ -81,13 +90,56 @@ async.waterfall([ |
81 | } | 90 | } |
82 | }); | 91 | }); |
83 | for(i of movie_data){ | 92 | for(i of movie_data){ |
84 | - if(Object.keys(i).length==4){ | 93 | + if(Object.keys(i).length==3){ |
85 | movie_data[r++]['rate'] = '예매율 0%'; | 94 | movie_data[r++]['rate'] = '예매율 0%'; |
86 | } | 95 | } |
87 | } | 96 | } |
97 | + | ||
98 | + browser.close(); | ||
99 | + }, | ||
100 | + | ||
101 | +]) | ||
102 | + | ||
103 | + | ||
104 | +let userData = { | ||
105 | + 'Date': '', | ||
106 | + 'location':'' | ||
107 | +}; | ||
108 | +// const _sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay)); | ||
109 | +app.get('/Megabox', (req, res) => { | ||
110 | + | ||
111 | + res.send(movie_data); | ||
112 | + | ||
113 | +}) | ||
114 | + | ||
115 | +const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();//.setChromeOptions(new chrome.Options().headless()) | ||
116 | + | ||
117 | +app.post('/Megabox', (req, res) => {//사용자에게 Date와 location(영화관 장소) 받아옴 | ||
118 | + userData['Date'] = req.body.Date; | ||
88 | for(i of location_data){ | 119 | for(i of location_data){ |
89 | - console.log(i['동탄']) | 120 | + if(i['LocationName'] == req.body.location){ |
121 | + userData['location']=i['LocationNUm']; | ||
122 | + break; | ||
90 | } | 123 | } |
91 | - browser.close(); | ||
92 | } | 124 | } |
93 | -]) | 125 | + |
126 | + let PlayingMovieURL = booking_url + '?brchNo1='+userData['location']+'&playDe='+userData['Date'];//사용자 정보 바탕으로 해당 일자 영화관 영화 상영 여부 확인 | ||
127 | + | ||
128 | + appdriver.get(PlayingMovieURL); | ||
129 | + appdriver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 | ||
130 | + res.send(movie_data); | ||
131 | + | ||
132 | +}) | ||
133 | + | ||
134 | +app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 여부 객체에 넣음 | ||
135 | + | ||
136 | + let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); | ||
137 | + let n = 0; | ||
138 | + for (item of movie_list) { | ||
139 | + movie_data[n++]['running'] = await item.getAttribute('form-at') | ||
140 | + } | ||
141 | + | ||
142 | + res.send(movie_data); | ||
143 | +}) | ||
144 | + | ||
145 | +app.listen(23023); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment