-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
79 lines (66 loc) · 2.25 KB
/
index.js
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
const Nightmare = require("nightmare");
const vo = require('vo');
const nightmare = Nightmare({
show: true,
typeInterval: 20,
waitTimeout: 60000,
gotoTimeout: 60000
});
var run = function*() {
yield nightmare
.viewport(1024, 768)
.goto('https://www.facebook.com')
.type('#email', 'xxx@xxx.com')
.type('#pass', 'xxxxx')
.click('#loginbutton input')
.wait('div[role=feed]')
.evaluate(function () {
window.document.body.scrollTop = document.body.scrollHeight;
})
.wait(3000);
//todo we can make infinite loop
for (var i = 0; i < 2; i++) {
yield nightmare
.evaluate(function () {
var content = [];
document.querySelectorAll('div[role=feed] .fbUserPost').forEach(function (element) {
if (element.querySelector('h5')) {
var postVideo = null, postImage = null;
if (element.querySelector('video')) {
postVideo = element.querySelector('video').src
}
if (element.querySelector('a img')) {
postImage = element.querySelector('a img').src
}
content.push({
text: element.querySelector('.userContent').innerText,
video: postVideo,
image: postImage,
user: {
name: element.querySelector('h5').innerText,
link: element.querySelector('h5 a').href
}
})
}
});
return content;
})
.then(function (result) {
console.log(result)
});
yield nightmare
.refresh()
.evaluate(function () {
window.document.body.scrollTop = document.body.scrollHeight;
})
.wait('div[role=feed]')
.wait(3000)
}
yield nightmare.end();
};
vo(run)(function (err) {
if (err) {
console.dir(err);
}
console.log('done');
});