Skip to content

Instantly share code, notes, and snippets.

@gzagatti
Created October 12, 2021 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gzagatti/b9948e0ab7e045698626483fa3fe0ad5 to your computer and use it in GitHub Desktop.
Save gzagatti/b9948e0ab7e045698626483fa3fe0ad5 to your computer and use it in GitHub Desktop.
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