crawling_broadcasting.js
7.03 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var async = require('async');
var webdriver = require('selenium-webdriver');
var options = {desiredCapabilities: {browserName: 'chrome'}};
const {Builder, By, Key, until} = require('selenium-webdriver');
const fs = require('fs')
const screen = {
width: 640,
height: 480
};
var a=8000
var img_src_list = []
var text_list = []
var testStartRunTime = 0;
var testruntime = 0;
var time = 0;
module.exports = {
search_broadcasting :function(driver,url,name,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;
}
driver
.get("http://"+url)
.then(() => {
driver.findElement(webdriver.By.id('pagination_76'))
.then ( paginationBtn => {
paginationBtn.findElements(webdriver.By.className('bt_next'))
.then(Btn_next => {
driver.findElement(webdriver.By.id('listUI_76'))
.then(contentsUI => {
clickandget(function() {
Btn_next[0].click()
setTimeout(() => {
clickandget(function() {
Btn_next[0].click()
setTimeout(() => {
clickandget(function() {
Btn_next[0].click()
setTimeout(() => {
clickandget(function(){
Btn_next[0].click()
setTimeout(() => {
clickandget(function(){
fs.writeFileSync("./log/"+name+"_img_src_br.txt", '\ufeff' + img_src_list, {encoding: 'utf8'});
fs.writeFileSync("./log/"+name+"_title_br.txt", '\ufeff' + text_list, {encoding: 'utf8'});
setTimeout(() => {
callback()
}, 500);
})
}, testruntime*1000+800);
})
}, testruntime*1000+800);
},testruntime*1000+800)
}, testruntime*1000+800);
})
}, testruntime*1000+800);
})
function clickandget(_callback) {
testRunTimer()
Btn_next[0].isDisplayed().then(function(state) {
if(state) {
contentsUI.findElements(webdriver.By.tagName('li'))
.then(elems => {
elems.forEach(elem => {
elem.findElements(webdriver.By.tagName('img'))
.then(img => {
img[0].getAttribute('src')
.then(img_src => {
elem.findElements(webdriver.By.className('tit'))
.then (titles => {
titles.forEach(title => {
title.getText()
.then(text => {
text_list.push(text)
img_src_list.push(img_src)
if(text_list.length % 5 == 0) {
var testruntime = testRunTimer();
time = time+testruntime*1000
_callback()
}
})
})
})
})
})
})
})
}
else {
fs.writeFileSync("./log/"+name+"_img_src_br.txt", '\ufeff' + img_src_list, {encoding: 'utf8'});
fs.writeFileSync("./log/"+name+"_title_br.txt", '\ufeff' + text_list, {encoding: 'utf8'});
setTimeout(() => {
callback()
}, 500);
}
},function(err) {
fs.writeFileSync("./log/"+name+"_img_src_br.txt", '\ufeff' + img_src_list, {encoding: 'utf8'});
fs.writeFileSync("./log/"+name+"_title_br.txt", '\ufeff' + text_list, {encoding: 'utf8'});
setTimeout(() => {
callback()
}, 500);
})
}
})
})
})
})
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
}
}
//var driver = new webdriver.Builder()
//.forBrowser('chrome')
//.withCapabilities(webdriver.Capabilities.chrome())
//.build();
//search_broadcasting(driver,"people.search.naver.com/search.naver?where=nexearch&sm=tab_ppn&query=유재석&os=94702&ie=utf8&key=PeopleService","유재석",function() {
// console.log("B")
//})