crawling_samename.js 4.29 KB
var async = require('async');
var webdriver = require('selenium-webdriver');
//var options = {desiredCapabilities: {browserName: 'chrome'}};
var chrome = require('selenium-webdriver/chrome')
var Options = new chrome.Options();
Options.addArguments('headless')
Options.addArguments('disable-gpu')
//var JASON = require('jason')
//var util = require('util')
//var EventEmitter = require('events')
var check = 0
var testStartRunTime = 0;
var testruntime = 0;

const {Builder, By, Key, until} = require('selenium-webdriver');

var next_link_list = []
var src_list = []
var text_list = []
var return_list = []
module.exports = {
    first_search : function(driver,string) {
        
        function testRunTimer() {
            var today = new Date(); // 현재시간 얻기
            var runTime = today.getTime(); // 밀리세컨드 ( 1970/01/01 부터 현재까지의 시간을 밀리세컨드로 나타냄 )
            var rtn = 0;
        
            if (testStartRunTime == 0) {
                      testStartRunTime = runTime;
            } else {
                      rtn = (runTime - testStartRunTime) / 1000;
                      testStartRunTime = 0;
            }
            return rtn;
        } 
        let url1 = "https://people.search.naver.com/search.naver?sm=tab_hty&where=nexearch&query="+string+"&ie=utf8&x=0&y=0"
        driver
        .get(url1).then(() => {
            testRunTimer()
            driver
            .findElements(webdriver.By.className('result_profile'))
            .then(profiles => {
                profiles.forEach(profile => {
                    profile.findElements(webdriver.By.className('thmb'))
                    .then(links=> {
                        links.forEach(link => {
                            link.getAttribute('href')
                            .then(next_link => {
                                profile.findElements(webdriver.By.className('thmb_img'))
                                .then((imgs) => {
                                    imgs.forEach(img => {
                                        img.getAttribute('src')
                                        .then(src => {
                                            profile.findElements(webdriver.By.className('who'))
                                            .then(whos => {
                                                whos.forEach(who => {
                                                    who.getText()
                                                    .then(text => {
                                                        next_link_list.push(next_link)
                                                        src_list.push(src)
                                                        text_list.push(text)
                                                        testruntime += testRunTimer()
                                                        console.log(testruntime)
                                                        setTimeout(function() {
                                                            check++;
                                                            if(check==1) {
                                                                return_list.push(next_link_list)
                                                                return_list.push(src_list)
                                                                return_list.push(text_list)
                                                                console.log(testruntime)
                                                                setTimeout(function() {
                                                                    console.log(return_list)
                                                                    return return_list
                                                                },500)
                                                            }
                                                        },testruntime+1000)
                                                    })
                                                })
                                            })
                                        })
                                    })
                                })
                            })
                        })
                    })
                })
            })
        })
    }
}