-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_captura-elemento.js
36 lines (29 loc) · 945 Bytes
/
07_captura-elemento.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
//Objeto da API Webpage
var page = require('webpage').create();
//Objeto da API System
var system = require('system');
url = system.args[1];
if (url !== undefined ){
page.open(url, function(status){
//Avalia funções no contexto da página
var resposta = page.evaluate(function() {
//Seleção de todas as tags p
return document.querySelectorAll('p');
});
console.log("Total de parágrafos: "+resposta.length);
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 07_captura-elemento.js <URL>\n\r");
phantom.exit(0);
}