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

后端 未结 4 1344
感动是毒
感动是毒 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:22

    PhantomJS

    var page = require('webpage').create();
    page.open('http://github.com/', function () {
        page.render('github.png');
        phantom.exit();
    });
    

    This is how to get a screenshot in phantomJS, I've used phantomJS for some time now.

    You can find more information here.

    Selenium

    driver = webdriver.Chrome();
    driver.get('http://www.google.com');
    driver.save_screenshot('out.png');
    driver.quit();
    

    Hope this helps.

提交回复
热议问题