Skip to content

Instantly share code, notes, and snippets.

@rpromyshlennikov
Created January 28, 2020 13:01
Show Gist options
  • Save rpromyshlennikov/b3c8bed7c07eb0a4cd83f02f5cdebd74 to your computer and use it in GitHub Desktop.
Save rpromyshlennikov/b3c8bed7c07eb0a4cd83f02f5cdebd74 to your computer and use it in GitHub Desktop.
Convert HTML table to CSV
csv = []
var rows = document.querySelectorAll("table tr");
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++)
row.push(cols[j].innerText);
csv.push(row.join("|"));
}
@rpromyshlennikov
Copy link
Author

rpromyshlennikov commented Jan 28, 2020

Partially extracted from: https://codepen.io/malahovks/pen/gLxLWX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment