Showing
3 changed files
with
11 additions
and
36 deletions
1 | const chatbot = require("./app.js"); | 1 | const chatbot = require("./app.js"); |
2 | - | ||
3 | const request = require('request'); | 2 | const request = require('request'); |
4 | const cheerio = require('cheerio'); | 3 | const cheerio = require('cheerio'); |
5 | const puppeteer = require('puppeteer'); | 4 | const puppeteer = require('puppeteer'); |
6 | - | ||
7 | require('chromedriver'); | 5 | require('chromedriver'); |
8 | const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기 | 6 | const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기 |
9 | var webdriver = require('selenium-webdriver'); | 7 | var webdriver = require('selenium-webdriver'); |
10 | var By = webdriver.By; | 8 | var By = webdriver.By; |
11 | const chrome = require('selenium-webdriver/chrome');//크롬 사용시 | 9 | const chrome = require('selenium-webdriver/chrome');//크롬 사용시 |
12 | - | ||
13 | const async = require('async') | 10 | const async = require('async') |
14 | let express = require('express'); | 11 | let express = require('express'); |
15 | let app = express(); | 12 | let app = express(); |
... | @@ -17,27 +14,20 @@ let bodyParser = require('body-parser'); | ... | @@ -17,27 +14,20 @@ let bodyParser = require('body-parser'); |
17 | const { timeout } = require('async'); | 14 | const { timeout } = require('async'); |
18 | app.use(bodyParser.urlencoded({ extended: false })); | 15 | app.use(bodyParser.urlencoded({ extended: false })); |
19 | app.use(bodyParser.json()); | 16 | app.use(bodyParser.json()); |
20 | - | ||
21 | - | ||
22 | const booking_url = "https://megabox.co.kr/booking?"; | 17 | const booking_url = "https://megabox.co.kr/booking?"; |
23 | exports.booking_url = booking_url; | 18 | exports.booking_url = booking_url; |
24 | const rate_url = "https://www.megabox.co.kr/movie"; | 19 | const rate_url = "https://www.megabox.co.kr/movie"; |
25 | - | ||
26 | let r =0; | 20 | let r =0; |
27 | let movie_data = []; | 21 | let movie_data = []; |
28 | exports.movie_data = movie_data; | 22 | exports.movie_data = movie_data; |
29 | let location_data = []; | 23 | let location_data = []; |
30 | exports.location_data = location_data; | 24 | exports.location_data = location_data; |
31 | let index = 0; | 25 | let index = 0; |
32 | - | ||
33 | - | ||
34 | exports.init = ()=>{async.waterfall([//for 동기적 처리 | 26 | exports.init = ()=>{async.waterfall([//for 동기적 처리 |
35 | async () => { | 27 | async () => { |
36 | - | ||
37 | const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();// | 28 | const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();// |
38 | driver.get(booking_url); | 29 | driver.get(booking_url); |
39 | driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 | 30 | driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 |
40 | - | ||
41 | let seoul = await driver.wait(until.elementsLocated(By.css('#mCSB_4_container>ul>li>#btn'))); | 31 | let seoul = await driver.wait(until.elementsLocated(By.css('#mCSB_4_container>ul>li>#btn'))); |
42 | let Gyeonggi = await driver.wait(until.elementsLocated(By.css('#mCSB_5_container>ul>li>#btn'))); | 32 | let Gyeonggi = await driver.wait(until.elementsLocated(By.css('#mCSB_5_container>ul>li>#btn'))); |
43 | const Incheon = await driver.wait(until.elementsLocated(By.css('#mCSB_6_container>ul>li>#btn'))); | 33 | const Incheon = await driver.wait(until.elementsLocated(By.css('#mCSB_6_container>ul>li>#btn'))); |
... | @@ -50,7 +40,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 | ... | @@ -50,7 +40,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 |
50 | for (item of location_list[i]) { | 40 | for (item of location_list[i]) { |
51 | location_data[index++] = { | 41 | location_data[index++] = { |
52 | 'LocationName':await item.getAttribute("brch-nm"), | 42 | 'LocationName':await item.getAttribute("brch-nm"), |
53 | - 'LocationNUm' : await item.getAttribute("brch-no") | 43 | + 'LocationNum' : await item.getAttribute("brch-no") |
54 | } | 44 | } |
55 | // let location_name = await item.getAttribute("brch-nm"); | 45 | // let location_name = await item.getAttribute("brch-nm"); |
56 | // let location_num = await item.getAttribute("brch-no"); | 46 | // let location_num = await item.getAttribute("brch-no"); |
... | @@ -59,14 +49,12 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 | ... | @@ -59,14 +49,12 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 |
59 | // location_data[index++] = obj; | 49 | // location_data[index++] = obj; |
60 | } | 50 | } |
61 | } | 51 | } |
62 | - | ||
63 | let movie_list = await driver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); | 52 | let movie_list = await driver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); |
64 | r = 0; | 53 | r = 0; |
65 | for (item of movie_list) { | 54 | for (item of movie_list) { |
66 | //Using getAttribute to get the data | 55 | //Using getAttribute to get the data |
67 | movie_data[r++] = { | 56 | movie_data[r++] = { |
68 | 'rank' : r, | 57 | 'rank' : r, |
69 | - | ||
70 | 'title' : await item.getAttribute("movie-nm"), | 58 | 'title' : await item.getAttribute("movie-nm"), |
71 | 'movie_num':await item.getAttribute("movie-no"), | 59 | 'movie_num':await item.getAttribute("movie-no"), |
72 | } | 60 | } |
... | @@ -75,9 +63,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 | ... | @@ -75,9 +63,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 |
75 | driver.close(); | 63 | driver.close(); |
76 | 64 | ||
77 | }, | 65 | }, |
78 | - | ||
79 | async () => { | 66 | async () => { |
80 | - | ||
81 | r = 0; | 67 | r = 0; |
82 | const browser = await puppeteer.launch({ | 68 | const browser = await puppeteer.launch({ |
83 | headless: true | 69 | headless: true |
... | @@ -101,16 +87,16 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 | ... | @@ -101,16 +87,16 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 |
101 | movie_data[r++]['rate'] = '예매율 0%'; | 87 | movie_data[r++]['rate'] = '예매율 0%'; |
102 | } | 88 | } |
103 | } | 89 | } |
104 | - console.log("completed") | 90 | + |
105 | browser.close(); | 91 | browser.close(); |
92 | + console.log("Comepleted!"); | ||
106 | }, | 93 | }, |
107 | 94 | ||
108 | ])} | 95 | ])} |
109 | 96 | ||
110 | - | 97 | +let appdriver; |
111 | -const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build(); | ||
112 | - | ||
113 | exports.using_PlayingMovieURL = async(PlayingMovieURL) => { | 98 | exports.using_PlayingMovieURL = async(PlayingMovieURL) => { |
99 | + appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build(); | ||
114 | appdriver.get(PlayingMovieURL); | 100 | appdriver.get(PlayingMovieURL); |
115 | //appdriver.switchTo().frame(0) | 101 | //appdriver.switchTo().frame(0) |
116 | //frameBokdMBooking 프레임 가져옴 | 102 | //frameBokdMBooking 프레임 가져옴 |
... | @@ -118,24 +104,12 @@ exports.using_PlayingMovieURL = async(PlayingMovieURL) => { | ... | @@ -118,24 +104,12 @@ exports.using_PlayingMovieURL = async(PlayingMovieURL) => { |
118 | exports.geting_PlayingMovie= async() => { | 104 | exports.geting_PlayingMovie= async() => { |
119 | let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); | 105 | let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); |
120 | let n = 0; | 106 | let n = 0; |
107 | + console.log(movie_list); | ||
121 | for (item of movie_list) { | 108 | for (item of movie_list) { |
122 | - movie_data[n++]['running'] = await item.getAttribute('form-at') | 109 | + console.log(item.getAttribute('form-at')) |
110 | + movie_data[n++]['running'] = await item.getAttribute('form-at'); | ||
123 | } | 111 | } |
124 | - console.log("completed") | 112 | + console.log("Completed get Running"); |
125 | - | ||
126 | } | 113 | } |
127 | 114 | ||
128 | -app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 여부 객체에 넣음 | ||
129 | - | ||
130 | - // let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); | ||
131 | - // let n = 0; | ||
132 | - // for (item of movie_list) { | ||
133 | - // movie_data[n++]['running'] = await item.getAttribute('form-at') | ||
134 | - // } | ||
135 | - using_PlayingMovieURL('https://megabox.co.kr/booking?brchNo1=4451&playDe=20220606'); | ||
136 | - geting_PlayingMovie(); | ||
137 | - | ||
138 | - res.send(PlayingMovieList); | ||
139 | -}) | ||
140 | - | ||
141 | -app.listen(8000); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
115 | +app.listen(5000); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | "cheerio": "^1.0.0-rc.11", | 15 | "cheerio": "^1.0.0-rc.11", |
16 | "chromedriver": "^101.0.0", | 16 | "chromedriver": "^101.0.0", |
17 | "express": "^4.18.1", | 17 | "express": "^4.18.1", |
18 | + "express-async-handler": "^1.2.0", | ||
18 | "puppeteer": "^14.1.1", | 19 | "puppeteer": "^14.1.1", |
19 | "selenium-webdriver": "^4.1.2" | 20 | "selenium-webdriver": "^4.1.2" |
20 | } | 21 | } | ... | ... |
-
Please register or login to post a comment