I need to visit some independent URLs where the elements of the pages are loaded very slowly. It usually takes several minutes to make the entire page completely loaded. However, only a small portion of this page is useful. The useful part can be indicated by a certain selector on the page. Therefore, I would like to know whether I can tell puppeteer to stop wait for the page once the key selector has already appeared, to accelerator the speed of the . There are extensive answers tell us to use
await page.waitForSelector('.class_sample');
So I use it like this:
page = await browser.newgpae();
await page.goto('example.com/xxx.html');
await page.waitForSelector('.class_sample');`
However, it still stucks on the stage of page.goto()
. Sometimes pyppeteer reports a timeout error after 30s as the targeted page is too slow.
I've found that most of the examples about the method waitForSelector()
are put behind a .click()
method. My troublesome case is that the pages are independent of each other (example.com/xxxxx.html) and cannot be visit by a click on a link, so a waitForSelector()
method doesn't solve my problem yet.
Any suggestion would be greatly appreciated.