crawling_br_onair_date.js
2.92 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
var async = require('async');
var webdriver = require('selenium-webdriver');
var options = {desiredCapabilities: {browserName: 'chrome'}};
var JASON = require('jason')
const {Builder, By, Key, until} = require('selenium-webdriver');
var iconv = require('iconv-lite')
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=%EB%9F%B0%EB%8B%9D%EB%A7%A8"
driver
.get(url1).then(() => {
driver
.findElements(webdriver.By.className('brcs_detail'))
.then(broad_info => {
broad_info[0].findElement(webdriver.By.tagName('dl'))
.then(more_data => {
more_data.findElement(webdriver.By.tagName('dd'))
.then(one_line => {
one_line.findElement(webdriver.By.className("inline"))
.then(isbroad => {
isbroad.getText()
.then(isbroad_string => {
console.log(isbroad_string)
broadcasting=isbroad_string.substring(0,4)
isbroad = isbroad_string.substring(18,21)
br_date = isbroad_string.substring(23,24)
br_date = br_date + "요일"
br_time = isbroad_string.substring(26,34)
console.log(broadcasting,isbroad,br_date,br_time)
if(isbroad == "방영중") {
driver.findElement(webdriver.By.id('nx_query')).clear().then(( )=> {
//var buf = iconv.encode("편성표", "euc-kr")
//console.log(buf)
//var encodestr='';
//for(var i=0; i<buf.length;i++) {
// encodestr+='%'+buf[i].toString('16')
// }
//encodestr = encodestr.toUpperCase();
//console.log(iconv.encode(encodestr, 'EUC-KR').toString())
//console.log(encodestr)
var buf = iconv.encode('편성표','euckr')
var param = buf.toString('binary')
console.log(param)
driver.findElement(webdriver.By.id('nx_query')).sendKeys(broadcasting,br_date,param)
driver.findElement(webdriver.By.className('spnew ico_search')).click()
})
}
else {
}
})
})
})
})
})
})