sdfasdfasd.js 2.15 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')
var test1 = require('./crawling_samename')
const fs = require('fs')
var util = require('util')
var EventEmitter = require('events').EventEmitter;

var next_link_Array  = []
var img_src_Array = []

const {Builder, By, Key, until} = require('selenium-webdriver');
var driver = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeOptions(Options)
.build();

var First_Search = function(name) {
    var self=this;
    this.on('input', function() {
        
        if(fs.existsSync("./log/"+name+"_next_link.txt")) {
            const next_link = fs.readFileSync("./log/"+name+"_next_link.txt");
            const img_src = fs.readFileSync("./log/"+name+"_img_src.txt");
            next_link_Array = next_link.toString().split(',');
            img_src_Array = img_src.toString().split(',');
            driver.quit()
            console.log(next_link_Array)
            console.log(img_src_Array)
            
            setTimeout(function() {
                br_search.emit('click')
            },1000)
            
        }
        else {
            test1.first_search(driver,name,function() {
                const next_link = fs.readFileSync("./log/"+name+"_next_link.txt");
                const img_src = fs.readFileSync("./log/"+name+"_img_src.txt");
                next_link_Array = next_link.toString().split(',');
                img_src_Array = img_src.toString().split(',');
                br_search = new broadcasting_search(next_link_Array,"유재석",0)
                console.log(next_link_Array)
                console.log(img_src_Array)
                driver.quit()
                setTimeout(function() {
                    br_search.emit('click')
                },1000)
            })
        }
    })
}
util.inherits(First_Search,EventEmitter);
first_search1 = new First_Search("유재석")
first_search1.emit('input')