Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HTML tables to csv
// selects all table rows element in an HTML document ("tr").
$$("tr").map(
// for each row, select each table data element ("td").
(row) => Array.from(
row.querySelectorAll("td")
// for each data element return the inner text surrounded by quotes and stripped of line breaks.
).map(
(cell) => "'" + cell.innerText.replace("\n", " ") + "'"
// join same row elements with ","
).join(", ")
// join all rows with "\n"
).join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment