<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Table to csv + bookmarklet</title>
<link data-require="bootstrap-css@*" data-semver="3.0.0" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>table to .csv</h1>
<p>Bookmarklet:
<a class="label label-info" href="javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://pap.as/js/tabletocsv.js';})();">table
to .csv</a> <br><small>You could drag this to your bookmark bar and try it on any page. Any page with a table, then.</small></p>
</div>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Mark</td>
<td>Tompson</td>
<td>the_mark7</td>
</tr>
<tr>
<td>2</td>
<td>Ashley</td>
<td>Jacobs</td>
<td>ash11927</td>
</tr>
<tr>
<td>3</td>
<td>Audrey</td>
<td>Ann</td>
<td>audann84</td>
</tr>
<tr>
<td>4</td>
<td>John</td>
<td>Robinson</td>
<td>jr5527</td>
</tr>
<tr>
<td>5</td>
<td>Aaron</td>
<td>Butler</td>
<td>aaron_butler</td>
</tr>
<tr>
<td>6</td>
<td>Chris</td>
<td>Albert</td>
<td>cab79</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
(function() {
var script = document.createElement("script");
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js';
script.type = 'text/javascript';
document.getElementsByTagName("head")[0].appendChild(script);
var checkReady = function(callback) {
if (window.jQuery) {
callback(jQuery);
}
else {
window.setTimeout(function() { checkReady(callback); }, 100);
}
};
checkReady(function($) {
// Script from this guy: http://blog.fguy.com/2011/06/28/jquery-export-table-to-csv-file/
$.fn.exportAsCSV = function () {
var csv = [];
csv.push('"' + $("th", this).map(function () {
return $(this).text();
}).get().join('","') + '"');
$("tr:gt(0)", this).each(function () {
csv.push('"' + $("td", this).map(function () {
return $(this).text();
}).get().join('","') + '"');
});
location.href = "data:text/csv;charset=utf-8," + encodeURIComponent(csv.join("\r\n"));
return this;
};
$(document).find('table').exportAsCSV();
});
})();