-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15_mega-senna.js
44 lines (34 loc) · 1.13 KB
/
15_mega-senna.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
(function () {
'use strict';
//Objetos das APIs Webpage e Filesystem
var page = require('webpage').create();
var fs = require('fs');
//Arquivo de destino (formato JSON)
var filePath = 'megasena.json';
page.open('http://loterias.caixa.gov.br/wps/portal/loterias/landing', function(status) {
//Avalia funções no contexto da página
var json = page.evaluate(function() {
var items=document.getElementsByClassName("resultado-loteria mega-sena").item(0).getElementsByTagName("li");
var numbers="";
for (var j = 0; j < items.length; ++j) {
numbers += " "+items[j].innerText;
}
//Retorna objeto no padrão JSON
return {
loteria: document.getElementsByClassName("megasena nome-loteria")[0].innerText,
resultado: document.getElementsByClassName("zeta")[0].innerText,
numeros: numbers.trim()
};
});
//console.log(JSON.stringify(json,null,5));
//Grava arquivo JSON
var out = fs.open(filePath, 'w');
out.write(JSON.stringify(json,null,5));
out.close();
if(fs.exists(filePath)){
var time = new Date();
console.log(filePath+" criado em "+time);
}
phantom.exit(0);
});
}());