Skip to content

Instantly share code, notes, and snippets.

@dvdsmpsn
Forked from DeBraid/index.html
Created February 24, 2016 14:44
Show Gist options
  • Save dvdsmpsn/4acc43cfe4dbfb113038 to your computer and use it in GitHub Desktop.
Save dvdsmpsn/4acc43cfe4dbfb113038 to your computer and use it in GitHub Desktop.
Using Chrome DevTools to scrape HTML table and convert to JSON.
// ****************************************************
// USING JQUERY TO CONVERT HTML TABLE INTO JSON
// by Derek from www.cacheflow.ca
// Watch the video: http://youtu.be/DPOOIOU0zVA
// ****************************************************
// Step 1: Create keys for JSON object
var cols = $("#tableID thead tr th").map(function(){
return $(this).text();
});
// eliminate the extraneous strings from cols
var headers = cols.splice(10, cols.length);
// Fetch the data from the table body
var tableObject = $("#tableID tbody tr.tableClass").map(function(i){
var row = {};
$(this).find('td').each(function(i){
var rowName = headers[i];
row[rowName] = $(this).text();
});
return row;
}).get();
// convert object to JSON
JSON.stringify(tableObject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment