-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
126 lines (112 loc) · 2.64 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
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
/**
* Dependencies.
*/
var exec = require('child_process').exec;
/**
* Login to a LinkedIn account.
*
* @param {String} email
* @param {String} password
*/
var login = exports.login = function(email, password){
return function(nightmare) {
nightmare
.viewport(800, 1600)
.goto('https://www.linkedin.com/uas/login')
.type('#session_key-login', email)
.type('#session_password-login', password)
.click('#btn-primary')
.wait();
};
};
/**
* Perform a search.
*
* @param {String} type
* @param {String} query
*/
var search = exports.search = function(type, query) {
if (!type || type.length === 0) type = 'all';
type = type.toLowerCase();
return function(nightmare) {
nightmare
.exists('#main-search-box', function(ready) {
if (!ready) throw 'Search box not ready';
return;
})
.type('#main-search-box', query)
.click('.search-button')
.wait('#search-types')
.click('li > a[href*="' + type + '"]')
.wait(5000);
}
};
/**
* Filter search results.
*
* @param {Array} filter, ['United States']
*/
var filter = exports.filter = function(filters) {
return function(nightmare) {
nightmare
.exists('.search-results', function(ready) {
if (!ready) throw 'Search results not ready';
return;
});
filters.forEach(function(filter) {
nightmare
.click('label[title="' + filter + '"]')
.wait(5000);
});
}
};
/**
* Crawl X pages from search results.
*
* @param {Integer} pages leave blank for indefinite crawling.
*/
var crawl = exports.crawl = function(pages) {
var pages = pages || 10;
return function(nightmare) {
for (var i = 0; i < pages; i++) {
for (var j = 0; j < 10; j++) {
nightmare
.click('#results > li:nth-child(' + (j + 1) + ')')
.wait(5000)
.back();
}
nightmare
.click('#results-pagination > ul > li.next > a')
.wait(5000);
}
}
};
/**
* Connect with user.
*
* WIP
*
* @param {String} user username or URL or nightmare is already on user page
*/
var connect = exports.connect = function(user) {
return function(nightmare) {
nightmare
.exists('.button-primary', function(ready) {
if (!read) throw 'Connect button not ready';
return;
})
.click('.button-primary')
.wait('.btn-primary')
// Need to select how to i know this person OR fill in an email address
.click('.btn-primary')
.wait(1000);
}
};
/**
* Get an array of users who has viewed me.
*/
var viewedMe = exports.viewedMe = function() {
return function(nightmare) {
// WIP
}
};