Created
November 8, 2016 20:31
-
-
Save cbertelegni/c3f17099c3f589e8ac1e9298629db0e2 to your computer and use it in GitHub Desktop.
Escrapear datos desde la consola con Javascript: http://www.promiedos.com.ar/historialpartidosel.php?versus=Brasil
This file contains hidden or 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
/** | |
* Escrapear datos desde la consola con javascript | |
*/ | |
var wrap = document.querySelectorAll("div#contenido > div")[5]; | |
var tables = wrap.querySelectorAll("table tbody"); | |
var data = []; | |
tables.forEach(function(t){ | |
var r = []; | |
t.querySelectorAll("td").forEach(function(txt){ | |
r.push(txt.innerText.replace(/\n/g, "")); | |
}); | |
data.push(r); | |
}); | |
exportCsv(data); | |
function exportCsv(_data){ | |
var csv = []; | |
_data.forEach(function(d){ | |
csv.push(d.join("|")); | |
}); | |
csv = csv.join("\n"); | |
// console.log(csv); | |
var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv); | |
var downloadLink = document.createElement("a"); | |
downloadLink.href = uri; | |
downloadLink.download = document.title ? document.title.replace(/ /g, "_") + ".csv" : "data.csv"; | |
document.body.appendChild(downloadLink); | |
downloadLink.click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment