crawling_broadcasting.js
2.94 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
var async = require('async');
var webdriver = require('selenium-webdriver');
var options = {desiredCapabilities: {browserName: 'chrome'}};
const {Builder, By, Key, until} = require('selenium-webdriver');
const screen = {
width: 640,
height: 480
};
var a=0
var breaktheloop = false
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
let url = 'https://people.search.naver.com/search.naver?where=nexearch&query=%EC%9C%A0%EC%9E%AC%EC%84%9D&sm=tab_etc&ie=utf8&key=PeopleService&os=94702';
driver
.get(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 => {
contentsUI.findElements(webdriver.By.tagName('li'))
.then(elems => {
elems.forEach(elem => {
elem.getText()
.then(text => {
console.log(text)
})
})
})
clickandget()
function clickandget() {
Btn_next[0].isDisplayed().then(function(state) {
if(state) {
Btn_next[0].click()
sleep(500).then(()=> {
contentsUI.findElements(webdriver.By.tagName('li'))
.then(elems => {
elems.forEach(elem => {
elem.getText()
.then(text => {
console.log(text)
})
})
})
})
}
else {
console.log(state)
}
})
}
})
})
})
})
function getContentsandClickNext(callback) {
driver.findElement(webdriver.By.id('listUI_76'))
.then(contentsUI => {
contentsUI.findElements(webdriver.By.tagName('li'))
.then(elems => {
elems.forEach(elem => {
elem.getTex
})
})
})
}
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}