-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.mjs
More file actions
27 lines (22 loc) · 982 Bytes
/
test.mjs
File metadata and controls
27 lines (22 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { parse } from "node-html-parser";
const url = "https://www.home-assistant.io/integrations/zha";
const html = await (await fetch(url)).text();
const site = parse(html);
// Try various approaches
console.log("=== querySelector('article header+p') ===");
console.log(site.querySelector("article header+p")?.text);
console.log("\n=== querySelector('article header') then nextElementSibling ===");
const header = site.querySelector("article header");
console.log("header found:", !!header);
console.log("nextElementSibling:", header?.nextElementSibling?.text);
console.log("\n=== querySelector('article p') ===");
console.log(site.querySelector("article p")?.text);
console.log("\n=== All article children tags ===");
const article = site.querySelector("article");
if (article) {
for (const child of article.childNodes.slice(0, 15)) {
if (child.tagName) {
console.log(`<${child.tagName.toLowerCase()}> → ${child.text}`);
}
}
}