从 Apify 示例文档中,我可以看到,如果您使用console.log()within handlePageFunction,它会直接记录到终端控制台。Apify utils 也是如此log。例如:
handlePageFunction: async ({ request, page }) => {
console.log('This is logged to the terminal console');
log.info('So is this.')
...
}
但是,当我在handlePageFunction 中定义自己的函数时,我无法将任何内容记录到终端控制台。我希望 console.log 会转到浏览器控制台,但在 Apify 中,浏览器窗口会迅速出现和消失。(也可以使用根本不显示浏览器的 apify-cli。)
handlePageFunction: async ({ request, page }) => {
...
const myFunction = () => {
console.log('This disappears into the ether.');
log.info('This causes the script to fail with error, "log is not defined"');
}
myFunction();
}
如何在嵌套的 javascript 函数中使用 Apify utils.log?