Created
October 12, 2021 03:10
-
-
Save gzagatti/b9948e0ab7e045698626483fa3fe0ad5 to your computer and use it in GitHub Desktop.
HTML tables to csv
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
// 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