-
Notifications
You must be signed in to change notification settings - Fork 0
/
iMastersCalendarMonth.js
63 lines (53 loc) · 1.78 KB
/
iMastersCalendarMonth.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
var casper = require('casper').create();
var events = [];
var futureEvents = [];
var today = new Date();
var eventList = [];
var hasNext = true;
var day = today.getDate();
var month = today.getMonth()+1;
var year = today.getFullYear();
month = month < 10 ? '0' + month : month;
var page = 1;
var baseUrl = 'http://imasters.com.br/agenda/' + year + '/' + month;
var url = '';
var datePattern = /[0-9/]+/;
do {
url = baseUrl + '/?_paged=' + page
casper.echo('Acessing ' + url);
casper.start(url, function() {
casper.echo('1 - page loaded');
});
casper.waitForSelector('.location', function() {
casper.echo('2 - checking events');
eventList.push(casper.evaluate(function() {
var stringNA = 'Não disponível',
calendarEvents = [],
containers = Array.prototype.slice.call(document.querySelectorAll('section.published'));
containers.forEach(function(container) {
var qsA = container.querySelector('a'),
qsDate = container.querySelector('.date'),
qsLocation = container.querySelector('.location'),
qsH3 = container.querySelector('h3');
calendarEvents.push({
name: qsA ? qsA.title.trim() : qsH3.innerHTML.trim(),
date: qsDate ? qsDate.innerHTML.trim() : stringNA,
location: qsLocation ? qsLocation.innerHTML.trim() : stringNA,
url: qsA ? qsA.href.trim() : stringNA
});
});
page++;
hasNext = document.querySelectorAll('a.next').length > 0;
return calendarEvents;
}));
}, null, 30000);
} while (hasNext)
casper.run(function() {
casper.echo('4 - printing results\n');
casper.echo('Next ' + eventList.length + ' events:\n');
eventList.forEach(function(evt) {
casper.echo(evt.name + '\nQuando: ' + evt.date +
'\nOnde: ' + evt.location + '\nSite: ' + evt.url + '\n');
});
casper.exit();
});