page.Esevaluate运行数小时
我试图爬网站的内容,并且大部分时间都可以使用(几分钟内完成),但有时最多需要8个小时。我已经设法查明了问题,并且在页面上发射了。以无头模式查看网站= false,它只是无限加载(单击后)。另外,如果我在该页面上手动尝试“ document.queryselector”,它对我有用。
代码如下:
console.log("Test");
let value = await page.evaluate((sel) => {
let element = document.querySelector(sel);
return element? element.innerHTML: null;
},selector);
console.log("Test2");
我该怎么做才能防止它运行那么长时间(我会尝试为这种情况设置某种超时系统)? 还是在此部分中代码时如何跟踪时间?这部分之后的代码立即(仅在下班后)就无法运行。
I am trying to crawl the contents of a website and it works most of the time (finishes in minutes) but sometimes it takes up to 8 hours. I've managed to pinpoint the issue and it is fired in the page.evaluate part. Looking at the website in headless mode=false it just loads infinitely (after a click). Also if I manually try "document.querySelector" on that page that is stuck in loading, it works for me.
The code is the following:
console.log("Test");
let value = await page.evaluate((sel) => {
let element = document.querySelector(sel);
return element? element.innerHTML: null;
},selector);
console.log("Test2");
What can I do to prevent it from running that long (I would try to setup some kind of timeout system for this case)?
Or how could I track the time while the code is in this part? The code immediately after this part never runs (only after hours) probably because of the await.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该
等待Page.Waitforselector(SEL,{Waituntil:timeout})
首先评估You should
await page.waitForSelector(sel, { waitUntil:timeout })
first then evaluate