3

我写的爬虫在我的 PC 上完美运行,一个运行 node.js v14.4.0 的 windows 操作系统。

但是,当我尝试在 Ubunto 机器上运行 Digital Ocean Droplet 时,某些页面出现以下错误:Page crashed!信息不多。

这是打印错误的代码:

const handleClose = async (msg) =>{
        console.log(msg)
        page.close();
        browser.close();
        process.exit(1);
}

process.on("uncaughtException", (reason, p) => {
        const a = `Possibly Unhandled Exception at: Promise , ${p}, reason: , ${reason}`
        handleClose(a);
});

我该如何解决这个问题?什么可能导致它?因为它在我的 Windows PC 上运行良好。

4

1 回答 1

0

我添加了我在网上找到的和相关的所有内存配置:

const args = [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-infobars',
        '--window-size=1366,768',
        '--unlimited-storage',
        '--full-memory-crash-report',
        '--disable-dev-shm-usage',
        '--force-gpu-mem-available-mb',
        '--disable-gpu'
    ]

但这没有帮助。

感谢 pguardiario note,我只是将 Droplet 从 1G RAM 升级到 2G。这就是诀窍。

我觉得很奇怪,抓取一个简单的网站需要超过 1G,所以我猜 Puppeteer 需要大量资源来运行。

更新 我有另一个页面粉碎,但这次它与服务器使用所有内存有关。所以我从 Puppeteer 中删除了所有这些参数:

'--unlimited-storage',
'--full-memory-crash-report',
'--disable-dev-shm-usage',
'--force-gpu-mem-available-mb',
'--disable-gpu'

只剩下基本的:

const args = [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-infobars',
        '--window-size=1366,768'
]

而且现在很稳定。所以,我想这需要小心使用,如果不是真的需要,请删除。

于 2020-09-19T09:09:21.843 回答