-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawl.js
85 lines (76 loc) · 2.69 KB
/
crawl.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
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true })
var trucks = [];
nightmare
.goto("http://express.dat.com/a/secure/Logout.aspx")
.goto('https://express.dat.com/a/secure/login.aspx?app=3sixtyexpress')
.type('#ctl00_cphMain_txtUserName', 'dedicated2016')
.type("#ctl00_cphMain_txtPassword", "load2016")
.click('#ctl00_cphMain_btnSubmit')
.wait(1000)
.wait('#ctl00_bodyMain')
.click("#ctl00_Navigation_hplSearch")
.click("#ctl00_cphMain_AssetTypeToggle_lbSearchTruck")
.wait(1000)
.click("#ctl00_cphMain_locOrigin_txtLocationEntry")
.insert("#ctl00_cphMain_locOrigin_txtLocationEntry")
.wait(100)
.type("#ctl00_cphMain_locOrigin_txtLocationEntry", "Lisle, IL")
.wait(1000)
.click("#ctl00_cphMain_txtOriginRadius")
.insert("#ctl00_cphMain_txtOriginRadius")
.wait(100)
.type("#ctl00_cphMain_txtOriginRadius", 50)
.wait(1000)
.insert("#ctl00_cphMain_locDestination_txtLocationEntry")
.wait(100)
.type("#ctl00_cphMain_locDestination_txtLocationEntry", "Denver, CO")
.wait(100)
.insert("#ctl00_cphMain_txtDestinationRadius")
.wait(100)
.type("#ctl00_cphMain_txtDestinationRadius", 50)
.wait(1000)
.click("#ctl00_cphMain_btnSearch");
function grapSearchResults(results, done) {
nightmare
.wait("#ctl00_cphMain_pnlSearchResults")
.evaluate(function () {
var rows = [];
$("#resultSet tr").each(function() {
var cells = [];
$(this).find("td").each(function() {
cells.push($.trim($(this).text()));
});
rows.push(cells);
});
return rows;
})
.then(function (rows) {
results = results.concat(rows);
nightmare
.exists("#ctl00_cphMain_lbNextPageTop")
.then(function(isExistingNextPageButton) {
nightmare
.exists("#ctl00_cphMain_lbNextPageTop.aspNetDisabled")
.then(function(isNextPageButtonDisabled) {
if (isExistingNextPageButton && !isNextPageButtonDisabled) {
nightmare.click("#ctl00_cphMain_lbNextPageTop");
grapSearchResults(results, done);
}
else {
done(results);
}
});
});
});
return nightmare;
}
grapSearchResults([], function(results) {
console.log(results);
console.log(results.length);
setTimeout(function() {
nightmare.end();
}, 100);
})
//nightmare.end();
//console.log(trucks);