How do I generate a png file w/ selenium/phantomjs from a string?

后端 未结 4 1343
感动是毒
感动是毒 2020-12-18 04:42

I am using selenium/phantomjs to create png files of html in python. Is there a way to generate the png from an html string or filehandle (instead of a website)? I\'ve searc

4条回答
  •  盖世英雄少女心
    2020-12-18 05:33

    PhantomJS

    var page = require('webpage').create();
    page.content = '

    Hello world

    '; page.render('name.png');

    You set the content of the page using page.content Then you render it using page.render

    Example using phantomjs-node

    phantom.create(function (ph) {
      ph.createPage(function (page) {
          page.set('viewportSize', {width:1440,height:900})
    
          //like this
          page.set('content', html);
    
          page.render(path_to_pdf, function() { 
            //now pdf is written to disk.
            ph.exit();
          });
      });
    });
    

提交回复
热议问题