crawling_br_onair_date.js 2.42 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')
const fs = require('fs')

datalist = []

module.exports = {
    search_onairanddate: function(driver,string,callback) {
        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 => {
                                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)
                                datalist.push(broadcasting,isbroad,br_date,br_time)
                                
                                fs.writeFileSync("./log/"+string+"_br_isonair.txt", '\ufeff' + datalist, {encoding: 'utf8'});
                                for(var i =0; i<100; ) {
                                    
                                    if() {
                                        i++
                                    }
                                }
                                callback()
                            })
                        })
                    })
                })
            })
        })
        driver.findElement(webdriver.By.className('brcs_thumb'))
        .then(brcs_thumb => {
            brcs_thumb.findElements(webdriver.By.tagName('img'))
            .then( img => {
               img[0].getAttribute('src')
               .then(img_src => { 
                    datalist.push(img_src)
                })
            })
        })
    }
}