1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
export default async function getTeams() {
let url = "https://www.capfriendly.com";
let res = await fetch(url);
let html = await res.text();
let doc = new DOMParser().parseFromString(html, "text/html");
let table = doc.querySelector("table#cf_homepage__teamTable");
let headers = Array.from(table.querySelectorAll("th")).map(h => h.textContent.trim()).map(e => e === "" ? "?" : e);
let rawRows = Array.from(table.querySelectorAll("tr")).map(r => {
let cells = Array.from(r.querySelectorAll("td"));
let cellData = cells.map(cell => cell.textContent.trim());
let anchor = r.querySelector("a");
if (cellData.length > 0) {
let blerg = Object.fromEntries(headers.map((header, index) => [header, cellData[index]]));
blerg.URL = url + anchor.attributes.getNamedItem("href").value;
return blerg;
}
return null;
}).filter(Boolean);
return rawRows;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 12, 2024