gpt4 book ai didi

apify - 在 Apify 中,如何从嵌套函数中登录到控制台?

转载 作者:行者123 更新时间:2023-12-02 00:51:37 24 4
gpt4 key购买 nike

从 Apify 示例文档中,我可以看到,如果您使用 console.log()handlePageFunction ,它直接登录到终端控制台。 Apify 实用程序也是如此log .例如:

handlePageFunction: async ({ request, page }) => {
console.log('This is logged to the terminal console');
log.info('So is this.')
...
}


但是,当我在 handlePageFunction this 中定义自己的函数时,我无法将任何内容记录到终端控制台。我希望 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?

最佳答案

如果您在 page.evaluate 中使用定义的函数或在浏览器上下文中评估的任何其他函数 console.log在浏览器控制台中输出。如果你想在 Node.js 中显示浏览器日志,这应该适用于简单的日志记录。 ——

page.on('console', msg => console.log('PAGE LOG:', msg.text));

关于apify - 在 Apify 中,如何从嵌套函数中登录到控制台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57121262/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com