이혜인

modify getting playingmovielist

const chatbot = require("./app.js");
const request = require('request');
const cheerio = require('cheerio');
const puppeteer = require('puppeteer');
require('chromedriver');
const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기
var webdriver = require('selenium-webdriver');
var By = webdriver.By;
const chrome = require('selenium-webdriver/chrome');//크롬 사용시
const async = require('async')
let express = require('express');
let app = express();
......@@ -17,27 +14,20 @@ let bodyParser = require('body-parser');
const { timeout } = require('async');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const booking_url = "https://megabox.co.kr/booking?";
exports.booking_url = booking_url;
const rate_url = "https://www.megabox.co.kr/movie";
let r =0;
let movie_data = [];
exports.movie_data = movie_data;
let location_data = [];
exports.location_data = location_data;
let index = 0;
exports.init = ()=>{async.waterfall([//for 동기적 처리
async () => {
const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();//
driver.get(booking_url);
driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴
let seoul = await driver.wait(until.elementsLocated(By.css('#mCSB_4_container>ul>li>#btn')));
let Gyeonggi = await driver.wait(until.elementsLocated(By.css('#mCSB_5_container>ul>li>#btn')));
const Incheon = await driver.wait(until.elementsLocated(By.css('#mCSB_6_container>ul>li>#btn')));
......@@ -50,7 +40,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
for (item of location_list[i]) {
location_data[index++] = {
'LocationName':await item.getAttribute("brch-nm"),
'LocationNUm' : await item.getAttribute("brch-no")
'LocationNum' : await item.getAttribute("brch-no")
}
// let location_name = await item.getAttribute("brch-nm");
// let location_num = await item.getAttribute("brch-no");
......@@ -59,14 +49,12 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
// location_data[index++] = obj;
}
}
let movie_list = await driver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
r = 0;
for (item of movie_list) {
//Using getAttribute to get the data
movie_data[r++] = {
'rank' : r,
'title' : await item.getAttribute("movie-nm"),
'movie_num':await item.getAttribute("movie-no"),
}
......@@ -75,9 +63,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
driver.close();
},
async () => {
r = 0;
const browser = await puppeteer.launch({
headless: true
......@@ -101,16 +87,16 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
movie_data[r++]['rate'] = '예매율 0%';
}
}
console.log("completed")
browser.close();
console.log("Comepleted!");
},
])}
const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
let appdriver;
exports.using_PlayingMovieURL = async(PlayingMovieURL) => {
appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
appdriver.get(PlayingMovieURL);
//appdriver.switchTo().frame(0)
//frameBokdMBooking 프레임 가져옴
......@@ -118,24 +104,12 @@ exports.using_PlayingMovieURL = async(PlayingMovieURL) => {
exports.geting_PlayingMovie= async() => {
let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
let n = 0;
console.log(movie_list);
for (item of movie_list) {
movie_data[n++]['running'] = await item.getAttribute('form-at')
console.log(item.getAttribute('form-at'))
movie_data[n++]['running'] = await item.getAttribute('form-at');
}
console.log("completed")
console.log("Completed get Running");
}
app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 여부 객체에 넣음
// let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
// let n = 0;
// for (item of movie_list) {
// movie_data[n++]['running'] = await item.getAttribute('form-at')
// }
using_PlayingMovieURL('https://megabox.co.kr/booking?brchNo1=4451&playDe=20220606');
geting_PlayingMovie();
res.send(PlayingMovieList);
})
app.listen(8000);
\ No newline at end of file
app.listen(5000);
\ No newline at end of file
......
This diff is collapsed. Click to expand it.
......@@ -15,6 +15,7 @@
"cheerio": "^1.0.0-rc.11",
"chromedriver": "^101.0.0",
"express": "^4.18.1",
"express-async-handler": "^1.2.0",
"puppeteer": "^14.1.1",
"selenium-webdriver": "^4.1.2"
}
......