【问题标题】:how to perform nightmare on every request?如何对每个请求执行噩梦?
【发布时间】:2017-11-06 22:44:16
【问题描述】:

如何对每个请求执行噩梦?

下面的方法只运行一次,从第二次开始,脚本不再运行。它处于无限负载中。会是什么?

谢谢

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);
        });   

})

【问题讨论】:

  • 这可能是一场噩梦
  • 你的意思是它只运行一次?此外,您还应该在 catch 语句中调用 res.send

标签: node.js express nightmare


【解决方案1】:

它只运行一次,因为您在第一个请求中调用 .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);
        });   

})

【讨论】:

    猜你喜欢
    • 2017-08-04
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 2010-12-21
    • 2020-03-14
    • 2010-11-13
    相关资源
    最近更新 更多