main.js
5.96 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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')
const test2 = require('./crawling_broadcasting')
const test3 = require('./crawling_br_onair_date')
const test4 = require('./crawling_time')
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 driver_1 = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeOptions(Options)
.build()
var driver_2 = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeOptions(Options)
.build();
var driver_3 = 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')
var img_src_br_list = []
var title_list = []
var broadcasting_search = function(next_link,name,num) {
var self=this;
this.on('click', function() {
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(',');
driver_1.quit()
console.log(img_src_br_list)
console.log(title_list)
is_onair.emit('click_1')
}
else {
test2.search_broadcasting(driver_1,next_link[num].substr(9),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(',');
driver_1.quit()
console.log(img_src_br_list)
console.log(title_list)
is_onair.emit('click_1')
})
}
})
}
util.inherits(broadcasting_search,EventEmitter);
br_search = new broadcasting_search(next_link_Array,"유재석",0)
br_datalist = []
var isonair = function(num) {
var self = this
this.on('click_1',function() {
if(fs.existsSync("./log/"+title_list[num]+"_br_isonair.txt")) {
const img_src_br = fs.readFileSync("./log/"+title_list[num]+"_br_isonair.txt");
br_datalist = img_src_br.toString().split(',');
br_datalist[0] = br_datalist[0].trim()
console.log(br_datalist)
Search_detail_time.emit('click_2')
}
else {
test3.search_onairanddate(driver_2,title_list[num],function() {
const img_src_br = fs.readFileSync("./log/"+title_list[num]+"_br_isonair.txt");
br_datalist = img_src_br.toString().split(',');
br_datalist[0] = br_datalist[0].trim()
console.log(br_datalist)
Search_detail_time.emit('click_2')
})
}
})
}
util.inherits(isonair,EventEmitter);
is_onair = new isonair(11)
var detail_time_list = []
var search_detail_time = function(num) {
var self = this;
this.on('click_2',function() {
if(br_datalist[1] == "방영중") {
if(fs.existsSync("./log/"+title_list[num]+"_time_detail.txt")) {
const detail = fs.readFileSync("./log/"+title_list[num]+"_time_detail.txt");
detail_time_list = detail.toString().split(',');
console.log(detail_time_list)
}
else {
test4.search_broadcasting_time(driver_3,br_datalist[0],br_datalist[2],title_list[num],function(){
const detail = fs.readFileSync("./log/"+title_list[num]+"_time_detail.txt");
detail_time_list = detail.toString().split(',');
console.log(detail_time_list)
})
}
}
})
}
util.inherits(search_detail_time,EventEmitter);
Search_detail_time = new search_detail_time(11);