forked from lambtron/linkedinbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreeper.js
89 lines (74 loc) · 2.25 KB
/
creeper.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
78
79
80
81
82
83
84
85
86
87
88
89
var auth = {
user: "[email protected]",
pass: "rainforestqa"
};
var fs = require("fs");
var page = new WebPage(),
names = [],
stepIndex = 0;
/**
* From PhantomJS documentation:
* This callback is invoked when there is a JavaScript console. The callback may accept up to three arguments:
* the string for the message, the line number, and the source identifier.
*/
page.onConsoleMessage = function(msg, line, source) {
console.log('console:' + source + '/' + line + '> ' + msg);
};
/**
* From PhantomJS documentation:
* This callback is invoked when there is a JavaScript alert. The only argument passed to the callback is the string for the message.
*/
page.onAlert = function(msg) {
console.log('alert!!> ' + msg);
};
// FS to array.
function readLines(input, cb) {
var remaining = '';
input.on('data', function(data) {
remaining += data;
var index = remaining.indexOf('\n');
while (index > -1) {
var line = remaining.substring(0, index);
remaining = remaining.substring(index + 1);
cb(line);
index = remaining.indexOf('\n');
}
});
input.on('end', function() {
if (remaining.length > 0) {
cb(remaining);
}
});
}
function creep(names) {
// Log in.
page.open("https://www.linkedin.com/uas/login", function(status) {
if (status === "success") {
page.evaluate(function(auth) {
document.querySelector("#session_key-login").value = auth.user;
document.querySelector("#session_password-login").value = auth.pass;
document.querySelector("#login").submit();
console.log("Login submitted!");
}, auth);
console.log(" ..logging in.");
// Callback is executed each time a page is loaded...
window.setTimeout(function() {
var peek = function peek() {
for (var i = 0; i < names.length; i++) {
console.log("Navigating to " + names[i]);
page.open(names[i], function(status) {
console.log("Inside.");
});
}
};
var timerId = 0;
if (timerId)
window.clearInterval(timerId);
peek();
window.setInterval(peek, 10000);
}, 5000);
}
});
}
var input = fs.createReadStream('data/txt/linkedin-1.txt');
readLines(input, creep);