page.set('content') doesn't work with dynamic content in phantomjs

后端 未结 3 480
闹比i
闹比i 2021-01-22 11:28

I tried to use phantomjs for screen capturing my page with node-phantom bridge. Here is what I\'m trying:

 var phantom = require(\'node-phantom\');

 phantom.cre         


        
3条回答
  •  礼貌的吻别
    2021-01-22 12:15

    I am not sure why set content does not work, It seems to be a limitation of the phantomjs api. You can just use document.write.

    var phantom = require('node-phantom');
    
    phantom.create(function (err, ph) {
      return ph.createPage(function (err, page) {
        page.open("about:blank", function(err,status) {
          page.evaluate(function() {        
            document.write('

    Hello from html

    '); }); return page.render('./content.png', function (err) { ph.exit(); }); }); }); });

提交回复
热议问题