Skip to content

Instantly share code, notes, and snippets.

@rctay
Created April 14, 2015 15:50
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 rctay/d4c1e97aee49c5e2e946 to your computer and use it in GitHub Desktop.
Save rctay/d4c1e97aee49c5e2e946 to your computer and use it in GitHub Desktop.
www.sgxdata.pebbleslab.com scrape table to csv eg. for Excel
var rows_all = document.getElementsByTagName("table")[4].children[0].children
var rows = Array.prototype.slice.call(rows_all, 2)
var rows_data = rows.map(function(row) { return Array.prototype.map.call(row.children, function(c, i) { var v = c.innerText; return i===2 ? v.replace("\n"," ") : v }) })
// poor man's csv - doesn't handle values with the delimiter itself!
console.log(rows_data.map(function(c) { return c.join(",") }).join("\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment