Created
December 31, 2016 18:05
-
-
Save scriptype/1f4153930889232a6da11e97c9d18b27 to your computer and use it in GitHub Desktop.
Get data from Toplist-as-a-db
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
fetch('/list.htm') | |
.then(response => response.text()) | |
.then(html => { | |
var dom = document.createElement('div') | |
dom.innerHTML = html | |
var content = dom.querySelector('#content') | |
var table = content.querySelector('table tbody') | |
var list = Array.from(table.querySelectorAll('tr')).slice(1) | |
var entries = list.map(entry => { | |
var cell = entry.querySelector('td:nth-child(2)') | |
var links = cell.querySelectorAll('a') | |
var title = links[0].innerText | |
var data = links[1].innerText | |
var parsedData | |
try { | |
parsedData = JSON.parse(data) | |
} catch(e) { | |
parsedData = data | |
} | |
return { | |
title, | |
data: parsedData, | |
} | |
}) | |
console.log(entries) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment