crawling_time.js
2.59 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
var webdriver = require('selenium-webdriver');
const {Builder, By, Key, until} = require('selenium-webdriver');
const fs = require('fs')
var arr = []
var result_arr = []
var temp = []
var i=0
var check = 0
module.exports = {
search_broadcasting_time : function(driver,broadcast,day,findtitle, callback) {
let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=0&ie=utf8&query="+broadcast+"+"+day+"+편성표"
driver
.get(url1).then(() => {
driver
.findElements(webdriver.By.className('cont_inner type_day _scheduleArea'))
.then(contentsearch_section=> {
contentsearch_section[0].findElements(webdriver.By.tagName('tbody'))
.then(tbody => {
tbody[0].findElements(webdriver.By.tagName('tr'))
.then(trs => {
trs.forEach(tr => {
tr.getText()
.then(content => {
if(content.indexOf(findtitle) != -1) {
arr = content.toString().split('\n')
str(function() {
i++
if(i==2) {
fs.writeFileSync("./log/"+findtitle+"_time_detail.txt", '\ufeff' + result_arr, {encoding: 'utf8'});
callback()
}
})
function str(_callback) {
temp[i+0] = arr[0] + " " + arr[1].substr(0,2) + "분"
temp[i+1] = arr[1].substr(3)
result_arr.push(temp[i+0],temp[i+1])
if(arr.length == 3) {
temp[i+2] = arr[0] + " " + arr[2].substr(0,2) + "분"
temp[i+3] = arr[2].substr(3)
result_arr.push(temp[i+2],temp[i+3])
i++
}
setTimeout(() => {
_callback()
}, 500);
}
}
})
})
})
})
})
})
}
}