【问题标题】:How can NightmareJS return full html source code?NightmareJS 如何返回完整的 html 源代码?
【发布时间】:2017-05-12 09:44:54
【问题描述】:

我使用 nightmare 爬取了一个网页,在窗口中,我可以发现所有项目都已加载,但无法打印某些项目的 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!
 });

【问题讨论】:

  • 为我工作。您面临的具体问题是什么?

标签: node.js nightmare


【解决方案1】:

试试

.evaluate(function() {
              return document.body.innerHTML
              // return document.documentElement.outerHTML // alternative
})

【讨论】:

    猜你喜欢
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-11
    • 2017-06-02
    • 2021-12-15
    • 1970-01-01
    相关资源
    最近更新 更多