There is a webpage that has 129 parent node.
And each parent node has multiple children to the fourth level (order>family>genus>specie).
I want to Open-all nodes.
I saw some posts here with a script to do that.
But I have no idea how to use it.
Note : my actual purpose is to copy all the data with its nested format.
Ps I'm not a web-dev and that's not my website.
The following code will recursively expand all of the links then make a JSON out of it with the tree representation and then copy the JSON in your clipboard.
I set a timeout of 2 seconds for each tree to expand so that the children trees appear after the network request, so it will take 2 seconds * all of the available tree in that page, so you will have to wait a very long time for it to finish, if you have a fast connection you can reduce the timeout to 1 second to make it go faster.
function extractChilds(ulNode) {
return [...ulNode.childNodes].map(node => {
let data = {
title: node.querySelector('a')?.innerText?.trim()
}
let child = node.querySelector('ul');
if(child) {
data.childrens = extractChilds(child);
}
return data;
});
}
async function main() {
let done = false;
while(!done) {
for(const e of [...document.querySelectorAll('.jstree-closed')]) {
await new Promise(r => setTimeout(r, 2000))
e.querySelector('ins').click()
}
if(document.querySelectorAll('.jstree-closed').length === 0) done = true;
}
console.log('expanded all of the trees')
return extractChilds(document.querySelector("#classification > ul"));
}
main().then(copy);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.