gpt4 book ai didi

node.js - 如何对每个请求执行 Nightmare ?

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

如何对每个请求执行 Nightmare ?

下面的方法仅运行一次,从第二次开始,脚本不会运行。它承受着无限的负载。会是什么呢?

谢谢

app.get('/', (req, res) => {

nightmare
.goto('https://site.com.br')
.wait(() => {
return $('#url').text() !== ''
})
.evaluate(() => {

return $('#url').text()
})
.end()
.then((result) => {

res.send(result)

})
.catch((error) => {
console.error('Search failed:', error);
});

})

最佳答案

它仅运行一次,因为您是在结束实例的第一个请求上调用.end,并且以后将无法使用该实例。

删除该行,那应该没问题。

app.get('/', (req, res) => {

nightmare
.goto('https://site.com.br')
.wait(() => {
return $('#url').text() !== ''
})
.evaluate(() => {

return $('#url').text()
})
.end() // <-- remove this line
.then((result) => {

res.send(result)

})
.catch((error) => {
console.error('Search failed:', error);
});

})

关于node.js - 如何对每个请求执行 Nightmare ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47147103/

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