gpt4 book ai didi

node.js - Nightmarejs永远运行?

转载 作者:行者123 更新时间:2023-12-03 13:23:40 25 4
gpt4 key购买 nike

我在CentOS 7服务器(http://serverip:3000/)上运行了一个简单的Nightmare应用程序,它可以永远运行,尽管它通过一个简单的res.send('hello world')传递了,但没有返回任何结果。

我正在使用Node 6.11。相同的代码可以在本地PC上正常运行。

    const express = require('express')
const app = express()

app.get('/', function (req, res) {
//res.send('hello world'); => works fine for port 3000
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: false });

nightmare
.goto('https://www.google.com')
.wait('#searchform')
.evaluate(function () {
return (document.body.innerHTML);
})
.end()
.then(function (result) {
console.log(result);
})
.catch(function (error) {
console.error('Search failed:', error);
});
})

app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})

最佳答案

首先,Electron具有静态库依赖关系,您需要将其独立安装在服务器上。

另外,由于XVFB没有显示,因此需要使用XVFB运行 Node 服务器。 (https://www.x.org/archive/X11R7.6/doc/man/man1/Xvfb.1.xhtml)

该命令将最终看起来像这样。$ xvfb-run node <your-server>.js
我像这样在Ubuntu上安装一切:

apt-get install -y libgtk2.0-0 libnotify-bin libgconf-2-4 libnss3 libxss1 
x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
x11-apps clang libdbus-1-dev libgtk2.0-dev libnotify-dev libgnome-keyring-
dev libgconf2-dev libasound2-dev libcap-dev libcups2-dev libxtst-dev libxss1
libnss3-dev xvfb

您需要做等效的CentOS。

独立运行电子版以进一步调试 $ <your-project-directory>/node_modules/electron/dist/electron

关于node.js - Nightmarejs永远运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44879567/

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