-
Notifications
You must be signed in to change notification settings - Fork 0
/
caspertest.js
52 lines (46 loc) · 1.6 KB
/
caspertest.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
var casper = require('casper').create({
pageSettings: {
webSecurityEnabled: false
}
});
var x = require('casper').selectXPath;
var count;
casper.userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36")
casper.start('https://www.eride.ri.gov/eride2K5/AggregateAttendance/AttendanceReports.aspx', function() {
this.echo("Casper loaded.");
});
for(var j = 0; j < 84; j++) {
casper.then(function() {
count = this.evaluate(function() {
var elements = __utils__.findAll('#GridView1 tr');
return elements.length;
});
this.echo(count);
for(var i = 2; i <= count; i++) {
if (i < 10) {
var handle = '#GridView1_ctl0'+i+'_imgBtnXls';
} else {
var handle = '#GridView1_ctl'+i+'_imgBtnXls';
}
this.echo(handle);
if(this.exists(handle)) {
this.thenClick(handle);
}
}
});
casper.thenClick('a[title="Go to the previous month"]');
}
casper.on('resource.received', function(resource) {
casper.echo(resource.url);
if (resource.url.indexOf('DailyAbsenceData.csv') > -1) {
var filenamebits = resource.url.split('/');
var filename = filenamebits[filenamebits.length-1];
var year = filename.substr(4,4);
var month = filename.substr(0,2);
var day = filename.substr(2,2);
var rest = ".csv";
filename = year + "_" + month + "_" + day + rest;
casper.download(resource.url, filename);
}
});
casper.run();