last.js 2.4 KB
var async = require('async');
var webdriver = require('selenium-webdriver');
//var options = {desiredCapabilities: {browserName: 'chrome'}};
var chrome = require('selenium-webdriver/chrome')
var Options = new chrome.Options();
Options.addArguments('headless')
Options.addArguments('disable-gpu')
const fs = require('fs')
const test2 = require('./crawling_broadcasting')
var EventEmitter = require('events').EventEmitter;


var img_src_br_list = []
var title_list = []
var next_link_list=[]
var result_arr=[]
//broadcasting_search('https://people.search.naver.com/search.naver?where=nexearch&sm=tab_ppn&query=%EC%9C%A0%EC%9E%AC%EC%84%9D&os=94702&ie=utf8&key=PeopleService','유재석')

var driver_1 = new webdriver.Builder().forBrowser('chrome').withCapabilities(webdriver.Capabilities.chrome()).setChromeOptions(Options).build()

module.exports = {
     broadcasting_search : function(next_link,name) {
        return new Promise(function(resolve,reject) {
            if(fs.existsSync("./log/"+name+"_img_src_br.txt")) {
                const img_src_br = fs.readFileSync("./log/"+name+"_img_src_br.txt");
                img_src_br_list = img_src_br.toString().split(',');
                const title_br = fs.readFileSync("./log/"+name+"_title_br.txt");
                title_list = title_br.toString().split(',');
                const link_br = fs.readFileSync("./log/"+name+"_next_link_br.txt")
                next_link_list = link_br.toString().split(',');
                driver_1.quit()
                result_arr.push(img_src_br_list,title_list,next_link_list)
                resolve(result_arr)
            }
            else {
                test2.search_broadcasting(driver_1,next_link.substr(7),name,function() {
                    const img_src_br = fs.readFileSync("./log/"+name+"_img_src_br.txt");
                    img_src_br_list = img_src_br.toString().split(',');
                    const title_br = fs.readFileSync("./log/"+name+"_title_br.txt");
                    title_list = title_br.toString().split(',');
                    const link_br = fs.readFileSync("./log/"+name+"_next_link_br.txt")
                    next_link_list = link_br.toString().split(',');

                    driver_1.quit()
                    result_arr.push(img_src_br_list,title_list,next_link_list)
                    resolve(result_arr)
                })
            }
        })
    }
}