Last active
October 2, 2021 16:17
-
-
Save sh-sabbir/3a82a41251de12f4d299fd1a09ca4705 to your computer and use it in GitHub Desktop.
Scrape data from html using js. For example: http://www.bangladesh.gov.bd/site/view/upazila-list/%E0%A6%89%E0%A6%AA%E0%A6%9C%E0%A7%87%E0%A6%B2%E0%A6%BE%E0%A6%B8%E0%A6%AE%E0%A7%82%E0%A6%B9
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
var tables = document.getElementsByClassName('geotable'); | |
var data = {}; | |
for (var i = 0; i < tables.length; i++) { | |
var rows = tables.item(i).rows; | |
var localArray = []; | |
for (j = 0; j < rows.length; j++){ | |
var oCells = rows.item(j).cells; | |
var ups = oCells.item(1).getElementsByTagName('a'); | |
var upsArray = []; | |
for (k = 0; k < ups.length; k++){ | |
upsArray.push(ups.item(k).text); | |
} | |
localArray[oCells.item(0).innerText] = upsArray; | |
} | |
Object.assign(data,localArray); | |
} | |
console.log(JSON.stringify(data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment