app.js 2.4 KB
let express = require('express');
let app = express();
let request = require('request');
const asyncHandler = require('express-async-handler')
const { response } = require('express');

const puppeteer = require('puppeteer');
const cheerio = require('cheerio');


app.get('/LotteCinema', asyncHandler(async (req, res, next) => {
    
    const browser = await puppeteer.launch();

    const page = await browser.newPage();

    // 수집하고자 하는 URL을 입력
    await page.goto('https://www.lottecinema.co.kr/NLCHS/Movie/List?flag=1');


    let content = await page.content();
    let $ = cheerio.load(content, {decodeEntities: true});
    let data = [];
    const $bodyList =  $("#contents > div > ul.movie_list.type2").children("li");

    let i =0;
    $bodyList.each(function(elem){
        if($(this).find('a > em').text() != "AD"){
            data[i++]={
                rank : i,
                url: $(this).find('div.top_info > div > div > a').attr('href').replace(""),
                title : $(this).find(' div.btm_info > strong').text(),
                rate : $(this).find('div.btm_info > span > span.rate_info > em').text(),
                star : $(this).find('div.btm_info > span > span.star_info').text(),
            };
        }
    });
    await browser.close();
    
    res.send(data);
    //console.log(data);
}))

let server = app.listen(80);

// (async () => {
//     const browser = await puppeteer.launch();

//     const page = await browser.newPage();

//     // 수집하고자 하는 URL을 입력
//     await page.goto('https://www.lottecinema.co.kr/NLCHS/Movie/List?flag=1');


//     let content = await page.content();
//     let $ = cheerio.load(content, {decodeEntities: true});
//     let data = [];
//     const $bodyList =  $("#contents > div > ul.movie_list.type2").children("li");

//     let i =0;
//     $bodyList.each(function(elem){
//         if($(this).find('a > em').text() != "AD"){
//             data[i++]={
//                 rank : i,
//                 url: $(this).find('div.top_info > div > div > a').attr('href').replace(""),
//                 title : $(this).find(' div.btm_info > strong').text(),
//                 rate : $(this).find('div.btm_info > span > span.rate_info > em').text(),
//                 star : $(this).find('div.btm_info > span > span.star_info').text(),
//             };
//         }
//     });
//     await browser.close();
    
//     console.log(data);
// })();