我已经将我遇到的问题减少到这个最小的公共站点示例。单击“显示全部”按钮会触发更多网站在每个浏览器中可见,但不是在噩梦中:
var Nightmare = require('nightmare');
new Nightmare({timeout: 60000})
.viewport(1920, 10000)
.goto('http://mtv.de/charts/5-hitlist-germany-top-100')
.wait(10000)
.screenshot('before.png')
.click('div#content div.chart-container a.button.show-all')
.wait(20000)
.screenshot('after.png')
.run();
我对为什么这不起作用一无所知,我什至尝试用 触发点击jQuery('...').trigger('click')
,这在 Chrome 中有效,但在噩梦中无效.evaluate(...)
。这是运行上述示例的调试输出,没有任何异常:
nightmare queueing action "viewport" +0ms
nightmare queueing action "goto" +3ms
nightmare queueing action "wait" +0ms
nightmare queueing action "screenshot" +0ms
nightmare queueing action "click" +0ms
nightmare queueing action "wait" +0ms
nightmare queueing action "screenshot" +0ms
nightmare run +0ms
nightmare .setup() creating phantom instance with options {"timeout":60000,"interval":50,"weak":true,"loadImages":true,"ignoreSslErrors":true,"sslProtocol":"any","proxy":null,"proxyType":null,"proxyAuth":null,"cookiesFile":null,"webSecurity":true} +0ms
nightmare .setup() phantom instance created +588ms
nightmare .setup() phantom page created +4ms
nightmare .viewport() to 1920 x 10000 +2ms
nightmare .goto() url: http://mtv.de/charts/5-hitlist-germany-top-100 +2ms
nightmare .goto() page loaded: success +3s
nightmare .wait() for 10000ms +501ms
nightmare .screenshot() saved to before.png +10s
nightmare .click() on div#content div.chart-container a.button.show-all +2s
nightmare .wait() for 20000ms +11ms
nightmare .screenshot() saved to after.png +20s
nightmare .teardownInstance() tearing down +2s