last.js
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)
})
}
})
}
}