我正在使用无头浏览器构建一个爬虫,但现在我想对我的应用程序进行 dockerize,我已经在我的 docker 映像中安装了 chrome,但在运行脚本时它会抛出错误。
启动Chrome.js
const chromeLauncher = require('chrome-launcher');
chromeLauncher.launch({
port: 9222,
chromeFlags: ['--headless','--proxy-server=54.171.181.204:8888','--disable-web-security','--disable-gpu']
}).then(chrome => {
console.log(`Chrome debugging port running on ${chrome.port}`);
});
Err
(node:415) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: connect ECONNREFUSED 127.0.0.1:9222
(node:415) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
当我在命令行中运行它时,它会抛出这样的错误
Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
Trace/breakpoint trap
您可以尝试使用 Docker 映像,例如yukinying/chrome 无头浏览器或类似的:https://hub.docker.com/r/yukinying/chrome-headless-browser/ https://hub.docker.com/r/yukinying/chrome-headless-browser/
从描述来看:
此 docker 镜像包含 Linux Dev 通道 Chromium
(https://www.chromium.org/getting-involved/dev-channel https://www.chromium.org/getting-involved/dev-channel),与
无头运行所需的依赖项和命令行参数
模式。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)