Last active
March 23, 2020 19:44
-
-
Save Nabeelhassan/248da2eef15182d3479a31c69393f8ec to your computer and use it in GitHub Desktop.
wikiepdia: asia table data extractor
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
| // This gist extracts the 'Political geography' Table From https://en.wikipedia.org/wiki/Asia | |
| // Political geography table index | |
| table = document.querySelectorAll('.wikitable')[2]; | |
| header = Array.from(table.rows[0].cells).map(i => i.innerText); | |
| Flag = 0; | |
| Symbol = 1; | |
| data = []; | |
| for (var i = 1, row; row = table.rows[i]; i++) { | |
| //iterate through rows | |
| const obj = {}; | |
| for (var j = 0, col; col = row.cells[j]; j++) { | |
| //iterate through columns | |
| obj[header[j]] = [Flag].includes(j) ? col.firstChild.firstChild.href : [Symbol].includes(j) ? col.firstChild.href : col.innerText; | |
| } | |
| data.push(obj); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment