我有一个 puppeteer 项目,需要提交表单,然后等待下一页。问题是,要进入下一页,网站将进行大约 3-4 次重定向,然后才会开始加载实际内容。
Puppeteer 似乎陷入了中间的困境。
我该如何解决这个问题?
这是我的代码:
await page.goto('<url>/Login.html', {'waitUntil': 'networkidle0', timeout: 60000});
await page.click(USERID_SLCT);
await page.keyboard.type(creds.userId);
await page.click(PWD_SLCT);
await page.keyboard.type(creds.pwd);
await page.click(LOGINBTN_SLCT);
await page.waitForNavigation({'waitUntil': 'networkidle0'});
await timeout(240000); // wait for the redirects to be finished
await page.waitForSelector(BTN_SLCT, {timeout: 240000}); // make sure the page is loaded <-- would fail here
await page.screenshot({path: './screenshots/mainpage.png'});
最佳答案
我遇到了类似的问题,并通过等待所需页面中的特定选择器解决了该问题。
await page.waitForSelector('#manage-trips', { visible: true, timeout: 0 });
关于javascript - puppeteer 如何等待所有重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51601292/