crawling_samename.js
3.42 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var async = require('async');
var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome')
var Options = new chrome.Options();
Options.addArguments('headless')
Options.addArguments('disable-gpu')
const fs = require('fs')
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,callback) {
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 => {
next_link_list.push(next_link)
src_list.push(src)
//text_list.push(text)
testruntime += testRunTimer()
setTimeout(function() {
check++;
if(check==1) {
//return_list.push(text_list)
setTimeout(function() {
fs.writeFileSync("./log/"+string+"_next_link.txt", next_link_list, {encoding: 'utf8'});
fs.writeFileSync("./log/"+string+"_img_src.txt", src_list, {encoding: 'utf8'});
callback()
},500)
}
},testruntime*1000+1000)
})
})
})
})
})
})
})
})
})
}
}