-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape-d3-data.js
36 lines (35 loc) · 1.06 KB
/
scrape-d3-data.js
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
28
29
30
31
32
33
34
35
36
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://w3c.github.io/aria/', {
waitUntil: 'domcontentloaded',
});
const tree = await page.evaluate(() => {
const recurseRoles = (roleSection, parent) => {
const roleId = roleSection.id;
const postfix = roleSection.querySelectorAll('.role-parent li').length > 1 ? ' (*)' : '';
const roleEntry = {
name: `${roleId}${postfix}`,
children: [],
};
if (parent) {
parent.children.push(roleEntry);
}
roleSection
.querySelectorAll('.role-children a.role-reference')
.forEach((link) => {
recurseRoles(
document.querySelector(link.getAttribute('href')),
roleEntry
);
});
return roleEntry;
};
const roleType = document.querySelector('#roletype');
const result = recurseRoles(roleType);
return result;
});
console.log(JSON.stringify(tree));
await browser.close();
})();