Docker中如何运行无头浏览器?
我正在用无头浏览器构build一个爬虫但是现在我想要dockerize我的应用程序我已经在我的docker镜像中安装了chrome但是在运行这个脚本的时候它会抛出一个错误。
StartChrome.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}`); });
呃
(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
您可以尝试使用像yukinying / chrome-headless-browser或类似的Docker镜像: https : //hub.docker.com/r/yukinying/chrome-headless-browser/
从描述:
这个docker镜像包含Linux开发通道Chromium( https://www.chromium.org/getting-involved/dev-channel ),具有所需的依赖关系和运行无头模式的命令行参数。
- 我可以在chrome devtools中执行nodejs javascript脚本吗?
- 使用无头铬来拦截图像请求数据
- V8 javascript:chrome vs node.js – “this”上下文的区别
- Chrome:缓慢'初始连接'到EC2
- socket.emit在手机浏览器中无法正常工作(但在隐身模式下工作)
- 如何在没有转译器的情况下在Node和浏览器中获取模块?
- 茉莉花是在量angular器超时,Selenium服务器之后崩溃(问题出现在Chrome浏览器,Firefox – 确定)
- Node.js,Javascript:node-debug不会检测Google Chrome
- 在Javascript中,为什么Object.getPrototypeOf()返回一个空列表?