function get_results(wiki) {
return [...wiki.querySelectorAll("table.wikitable.plainrowheaders")]
.map(table => ({
constituency: table.querySelector("caption")
.textContent
.replace(/\(.*\)/g, "")
.replace(/\[.*\]/g, "")
.replace(/ & /g, " and ")
.replace(/^St\./g, "St")
.trim(),
seats: /2/.test(table.querySelector("caption").textContent) ? 2 : 1,
results: [...table.querySelectorAll("tr")]
.map(row => [...row.querySelectorAll("td")]
.map(cell => cell.textContent.trim()))
.filter(row => row.length === 6)
}))
.flatMap(d => d.results
.map(c => ({
constituency: d.constituency,
seats: d.seats,
party: c[1],
candidate: c[2].replace(/ \*$/, ""),
votes: parseInt(c[3].replace(",", ""))
})))
}