【发布时间】:2017-05-16 18:23:18
【问题描述】:
使用 nightmareJS,如果超过 waitTimeout 限制,有什么方法可以调用函数?现在它正在给我一个承诺拒绝警告
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: .wait() timed out after 10000msec
我想知道如果收到此错误,是否有任何方法可以调用函数。我的代码结构如下:
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true, waitTimeout: 10000});
nightmare.goto(my_url);
nightmare.wait(my_element);
nightmare.evaluate(function() {...});
nightmare.then(function(result) {...code that could give a promise warning...});
我可以在 goto 和 then 语句中添加一个 catch 子句(正如 Belfordz 建议的那样),这会起作用,但是 then 语句中还有其他嵌套的 then 语句。我更喜欢一个可以捕获任何 Promise 警告或抛出的超时错误的语句。
【问题讨论】:
-
听起来你只需要在承诺拒绝的内容中添加一个 catch 子句
标签: javascript web-scraping phantomjs nightmare