2017-05-12 30 views
0

我使用噩梦来抓取网页,在窗口中,我可以找到所有项目都被加载,但无法打印某些项目的html代码。NightmareJS如何返回完整的html源代码?

有什么建议吗?

我的代码。

var Nightmare = require('nightmare'); 

var nightmare = Nightmare({ 
    show: true, 
    webPreferences: {}}) 

nightmare 
.goto('http://music.163.com/') 
.viewport(1600, 900) 
.wait(5000) 
.evaluate(function() { 
    return document.documentElement.innerHTML; 
}) 
.end() 
.then(function(res) { 
    console.log('source code:', res); // not all the html code printed! 
}); 
+0

为我工作。你面对什么确切的问题? – devilpreet

回答

0

尝试

.evaluate(function() { 
       return document.body.innerHTML 
       // return document.documentElement.outerHTML // alternative 
}) 
相关问题