crawling_br_onair_date.js 3.33 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, url, string, callback) {
        driver
        .get(url).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.findElement(webdriver.By.tagName("a"))
                            .then(a => {
                                a.getText()
                                .then(text=> {
                                    isbroad.getText()
                                    .then(day => {
                                        isbroad.findElement(webdriver.By.className("broad_txt"))
                                        .then(b => {
                                            b.getText()
                                            .then(text2 => {
                                                if(day.indexOf('(') != -1) {
                                                    var day_ = day[day.indexOf('(')+1]
                                                }
                                                datalist.push(text)
                                                datalist.push(text2)
                                                datalist[3] = day_
                                                setTimeout(() => {
                                                    fs.writeFileSync("./log/"+string+"_br_isonair.txt", datalist, {encoding: 'utf8'});
                                                    
                                                    callback()
                                                }, 500);
                                            })
                                        })
                                    })
                                })
                            })
                        })
                    })
                })
            })
        })
        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[2] = img_src
                })
            })
        })
    }
}

//    
//var driver = new webdriver.Builder()
//.forBrowser('chrome')
//.withCapabilities(webdriver.Capabilities.chrome())
//.build();
//
//search_onairanddate(driver,"https://search.naver.com/search.naver?where=nexearch&sm=ppl_cts&mra=bjkw&x_csa=%7B%22pkid%22%3A%2257%22%2C%22os%22%3A%22659910%22%7D&pkid=57&os=659910&query=%EB%AC%B4%ED%95%9C%EB%8F%84%EC%A0%84","무한도전",function() {
//    console.log("B")
//})