Created
March 24, 2014 18:13
-
-
Save pmarques/9745868 to your computer and use it in GitHub Desktop.
Print in browser console the ordered result of a scan in a table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var DEBUG = false; | |
// XPath Selector | |
var $x = function (path) { | |
var r = document.evaluate(path, document, null, 9, null).singleNodeValue | |
return !!r ? [r] : []; | |
}; | |
var values = []; | |
// Scrapper | |
var i = $x('//*[@id="availabilitydetails"]/table/tbody')[0].childNodes.length; | |
while( --i ) { | |
var nStr = '//*[@id="' + i + '"]/table/tbody/tr/td[2]'; | |
if( $x(nStr).length <= 0 ) { | |
continue; | |
} | |
var name = $x(nStr)[0].textContent; | |
var tStr = '//*[@id="graph' + i + '"]/table/tbody/tr[2]/td[2]'; | |
var t = -1; | |
if( $x(tStr).length > 0) { | |
t = $x(tStr)[0].textContent; | |
t = parseFloat( t.replace( ',', '') ); | |
} | |
DEBUG && | |
console.log( | |
name, | |
t | |
); | |
var result = { | |
city : name, | |
time : t | |
}; | |
var j = 5; | |
var TYPES = [ | |
'', | |
'DNS', | |
'Connection', | |
'FirstByte', | |
'LastByte' | |
] | |
while( --j ) { | |
var tt = '//*[@id="graph' + i + '"]/table/tbody/tr[2]/td[1]/table/tbody/tr/td[' + j + ']'; | |
m = -1; | |
if( $x(tt).length > 0) { | |
var v = $x(tt)[0].title.replace(',',''); | |
m = v.match( /.*:\s(\d+)\s.*/ )[1]; | |
} | |
result[ TYPES[j] ] = parseFloat( m ); | |
} | |
values.push( result ); | |
} | |
// Sort values | |
values.sort( function( a, b ) { | |
return a.time - b.time; | |
} ); | |
// Print as a table | |
console.table( values ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment