【问题标题】:How to end NightmareJs instance after chaining promises?链接承诺后如何结束 NightmareJs 实例?
【发布时间】:2016-11-27 19:25:12
【问题描述】:

我在文档中看到的示例在使用 .then() 之前调用 .end()。 比如

nightmare
  .goto('http://yahoo.com')
  .type('form[action*="/search"] [name=p]', 'github nightmare')
  .click('form[action*="/search"] [type=submit]')
  .wait('#main')
  .evaluate(function () {
    return document.querySelector('#main .searchCenterMiddle li a').href
  })
  .end()
  .then(function (result) {
    console.log(result)
  })
  .catch(function (error) {
    console.error('Search failed:', error);
  });

但是,我正在尝试这样做......

...
.then(function () {...})
.end()

但我收到一条错误消息,指出 .end 不存在。

我也尝试了下面的方法,它不会抛出错误但会导致噩梦挂起。

...
.then(function () {...})
.then(function () {
  nightmare.end()
});

【问题讨论】:

    标签: javascript node.js web-scraping nightmare


    【解决方案1】:

    根据Github issue discussion

    nightmare.end() 必须从链式 .then() 中返回,而不仅仅是调用。

    ...
    .then(function () {...})
    .then(function () {
      return nightmare.end();
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2020-05-10
      • 2015-04-15
      • 2023-01-27
      • 2019-05-24
      • 2015-01-06
      • 1970-01-01
      相关资源
      最近更新 更多