Skip to content

Instantly share code, notes, and snippets.

@nenkoru
Created June 24, 2023 20:44
Show Gist options
  • Save nenkoru/4cf5423612c3a010649032f35b0471c0 to your computer and use it in GitHub Desktop.
Save nenkoru/4cf5423612c3a010649032f35b0471c0 to your computer and use it in GitHub Desktop.
Parse games compatibility from yuzu
let xhr = new XMLHttpRequest();
xhr.open("GET", "https://yuzu-emu.org/game/", false)
xhr.send()
parser = new DOMParser();
yuzuDocument = parser.parseFromString(xhr.response, 'text/html');
function extractInnerTextFromNodes(nodes, childElement) {
var texts = []
for(var i = 0; i < nodes.length - 1; i++) {
texts.push(nodes[i].querySelector(childElement).innerText);
}
return texts
}
games = yuzuDocument.querySelectorAll("td[class=game-title]")
compats = yuzuDocument.querySelectorAll("td[class=compatibility]")
dates = yuzuDocument.querySelectorAll("td[class=date-tested]")
games = extractInnerTextFromNodes(games, "a")
compats = extractInnerTextFromNodes(compats, "span")
dates = extractInnerTextFromNodes(dates, "span")
gamesCompatDict = {}
for (var i = 0; i < games.length - 1; i++) {
gamesCompatDict[games[i]] = compats[i];
}
@nenkoru
Copy link
Author

nenkoru commented Jun 24, 2023

Nowhere near a js developer, hence a 'false' in a http request
So any enhancements are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment