Hello. Here is the problem of my code.
There is a html content with pages labels on the bottom , I can click the page labels, then the content changed.
I'm using js code to simulate this operation , click each page label , then fetch the content displayed and something like that.
BUT , It seemed the content did not updated immidiately , the content fetched repeat the first page.
The fetching operation should be done after the page content has been changed. I tried the 'Promise', seems not code correct, the result just not right.
What I have tried:
if(window.location.href.includes('https://www.hide-my-ip.com/proxylist.shtml')) {
for( var i of document.querySelectorAll('span a.paginate_button')) {
new Promise((resolve,reject) => {
i.click();
resolve();
}).then( () => {
console.log("current page index :"+ document.querySelector('.current').innerText);
for(var item of document.querySelector('table tbody').children) {
item = item.children;
console.log(item[0].innerText + ':' + item[1].innerText);
}
});
};
}
As the comment referred , Mutation observer can somehow deal with it.
if(window.location.href.includes('https://www.hide-my-ip.com/proxylist.shtml')) {
new MutationObserver(function(mutation,observer) {
for(let mu of mutation) {
if(mu.addedNodes.length > 0) {
for(var item of document.querySelector('table tbody').children) {
item = item.children;
console.log(item[0].innerText + ':' + item[1].innerText);
}
}
}
var curr_pageidx=parseInt(document.querySelector('.current').innerText);
var next_pageidx=curr_pageidx+1;
var page_nodes=document.querySelectorAll('span a.paginate_button');
for(let idx=0;idx<page_nodes.length;idx++) {
if(parseInt(page_nodes[idx].innerText) == next_pageidx) {
page_nodes[idx].click();
break;
}
}
}).observe(document.querySelector('tbody'),{childList: true});
}