crawling_br_onair_date.js 3.03 KB
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')

module.exports = {
    search_onairanddate: function(driver,string) {
        let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=" + string
        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 {

                                }
                            })
                        })
                    })
                })
            })
        })
    }
}