crawling_time.js
3.21 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
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
//var driver = new webdriver.Builder().forBrowser('chrome').withCapabilities(webdriver.Capabilities.chrome()).build();
//search_broadcasting_time(driver,"SBS","일요일","런닝맨",function() {})
module.exports = {
search_broadcasting_time :function (driver,broadcast,day,findtitle, callback) {
let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query="+broadcast.toLowerCase()+"+"+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')
console.log(arr)
str(function() {
i++
if(i==1) {
R=[]
R[0] = result_arr[0]
R[1] = result_arr[1]
R[2] = result_arr[2]
fs.writeFileSync("./log/"+findtitle+"_time_detail.txt", '\ufeff' + R, {encoding: 'utf8'});
callback()
}
})
function str(_callback) {
temp[0] = arr[0].substr(0,2)
temp[1] = arr[1].substr(0,2)
temp[2] = findtitle
result_arr.push(temp[0],temp[1],temp[2])
//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);
}
}
})
})
})
})
})
})
}
}