1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export async function getPaginationNumbers(
html: string
): Promise<[number, number] | [null, null]> {
const { DOMParser, Node } = await import(
"https://deno.land/x/deno_dom/deno-dom-wasm.ts"
);
const parser = new DOMParser();
const regex = /Page\s+(\d+)\s+of\s+(\d+)/i;
const document = parser.parseFromString(html, "text/html");
const node = document.querySelector("td.NumericPages > div.rgInfoPart");
console.log(node);
if (node) {
const match = node.textContent.match(regex);
console.log(match);
if (match) {
return [parseInt(match[1]), parseInt(match[2])];
}
}
return [null, null];
}
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!
October 23, 2023