-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13_conta-elementos.js
55 lines (42 loc) · 1.8 KB
/
13_conta-elementos.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
//Objeto da API Webpage
var page = require('webpage').create();
//Objeto da API System
var system = require('system');
url = system.args[1];
if (url !== undefined ){
//Habilita
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open(url, function(status) {
page.evaluate(function() {
//Unifica os textos de todas as tags parágrafo
text="";
p = document.querySelectorAll("p");
for(i = 0; i < p.length; i++){
text = text + p[i].innerText;
}
//Imprime as contabilizações
console.log('---[ Análise SEO ]----------------------------------------------------------------');
console.log('Presença de uma tag h1: '+ ((document.querySelectorAll('h1').length == 1) ? "Sim" : "Não"));
console.log('Presença de um meta description: '+ (document.querySelectorAll("meta[name=description]").length == 1 ? "Sim" : "Não"));
console.log('Tamanho do h1: '+ document.querySelectorAll('h1')[0].innerText.length + ' caracteres [Recomendado ter até 65 caracteres]');
console.log('Tamanho do meta description: '+ document.querySelectorAll("meta[name=description]")[0].content.length + ' caracteres [Recomendado ter até 165 caracteres]');
console.log('Tamanho do texto: '+ text.split(" ").length + ' palavras [Recomendado ter pelo menos 300 palavras]');
});
phantom.exit(0);
});
page.onError = function(msg, trace) {
var msgStack = ['Erro: ' + msg];
if (trace && trace.length) {
msgStack.push('Local do erro:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
});
}
//console.error(msgStack.join('\n'));
};
} else {
console.log("\nUso: phantomjs 13_conta_elementos.js <URL>\n\r");
phantom.exit(0);
}