-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiMastersCalendarNextTen.js
More file actions
40 lines (34 loc) · 1.25 KB
/
iMastersCalendarNextTen.js
File metadata and controls
40 lines (34 loc) · 1.25 KB
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
var casper = require('casper').create();
var eventList = [];
casper.start('http://imasters.com.br/agenda/', function() {
casper.echo('1 - page loaded');
});
casper.waitForSelector('.location', function() {
casper.echo('2 - checking events');
eventList = 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');
calendarEvents.push({
name: qsA ? qsA.title.trim() : stringNA,
date: qsDate ? qsDate.innerHTML.trim() : stringNA,
location: qsLocation ? qsLocation.innerHTML.trim() : stringNA,
url: qsA ? qsA.href.trim() : stringNA
});
});
return calendarEvents;
});
}, null, 30000);
casper.run(function() {
casper.echo('3 - 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();
});