Forked from hayatbiralem/gist:eb25df49899cd1f97616ce72253724e0
Created
August 29, 2025 18:30
-
-
Save acurtis517/b51e00bfc94fa733bd0fafab70b1f336 to your computer and use it in GitHub Desktop.
Revisions
-
hayatbiralem created this gist
Jul 14, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ // Thanks to this gist: [Sample HTML/JS to parse a Google Spreadsheet](https://gist.github.com/terrywbrady/a03b25fe42959b304b1e) var htmlEndPoint = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vREXBtuL2uKofq9ufXsIlytbONUR0-q_tf1Ucm14JpeE5KAdry97CCwvivf3e5NkCAnZ1Xg4qYa0RCo/pubhtml'; (function($){ var parseHtmlTableToJson = function($table){ var data = []; var $headers = $("tr:first-child td", $table); var headers = []; $headers.each(function(){ headers.push($(this).text().trim()); }); var $rows = $("tr:first-child ~ tr", $table).each(function(index) { data[index] = {}; $(this).find("td").each(function(cellIndex) { data[index][headers[cellIndex]] = $(this).html(); }); }); return data; }; var parseGoogleSpreadsheetHTMLIntoArray = function (response){ var sheets = {}; var bodyHtml = /<body.*?>([\s\S]*)<\/body>/.exec(response)[1]; console.log(bodyHtml); var $bodyHtml = $(bodyHtml); $bodyHtml.find('#sheet-menu a').each(function(index){ sheets[$(this).text().trim()] = parseHtmlTableToJson($bodyHtml.find('table').eq(index)); }); return sheets; }; $(document).ready(function(){ $.ajax( htmlEndPoint ) .done(function(response) { // console.log(response); var sheets = parseGoogleSpreadsheetHTMLIntoArray(response); console.log(sheets); }); }); })(jQuery);