Try/catch 处理程序的行为不一致
Try/catch handler not behaving consistantly
我在 Puppeteer 脚本中有以下错误处理程序。当 运行 from node
在我的电脑上时,它运行良好。但是,当来自 Apify Puppeteer-Scraper Actor 的 运行 时,只有在我取消注释 console.log(e)
时它才有效。如果不是,它将始终将 notfound
设置为 true
,而不管是否存在 foobar
class 元素。
let notfound = false;
try {
await page.waitForSelector('.foobar', { timeout: 10 });
} catch(e) {
// console.log(e);
console.log('Foobar not found.');
notfound = true;
}
在其他语言中,我会怀疑内存处理不当,但我不确定这里是否会出现这种情况?什么可以解释这种行为?
它不在原始问题中(我的错),但 waitForSelector()
有一个自定义超时:
await page.waitForSelector('.foobar', { timeout: 10});
现在这个超时是以毫秒为单位设置的,而不是以秒为单位。
显然 10 毫秒不足以让 Puppeteer 渲染 foobar
class 对象。增加这个值解决了这个问题。
我在 Puppeteer 脚本中有以下错误处理程序。当 运行 from node
在我的电脑上时,它运行良好。但是,当来自 Apify Puppeteer-Scraper Actor 的 运行 时,只有在我取消注释 console.log(e)
时它才有效。如果不是,它将始终将 notfound
设置为 true
,而不管是否存在 foobar
class 元素。
let notfound = false;
try {
await page.waitForSelector('.foobar', { timeout: 10 });
} catch(e) {
// console.log(e);
console.log('Foobar not found.');
notfound = true;
}
在其他语言中,我会怀疑内存处理不当,但我不确定这里是否会出现这种情况?什么可以解释这种行为?
它不在原始问题中(我的错),但 waitForSelector()
有一个自定义超时:
await page.waitForSelector('.foobar', { timeout: 10});
现在这个超时是以毫秒为单位设置的,而不是以秒为单位。
显然 10 毫秒不足以让 Puppeteer 渲染 foobar
class 对象。增加这个值解决了这个问题。