Convert URL to screenshot (script)

前端 未结 6 1669
深忆病人
深忆病人 2020-12-15 13:19

There is the URL of page on the Internet. I need to get a screenshot of this page (no matter in which browser).

I need a script (PHP, Python (even Django framework)

6条回答
  •  误落风尘
    2020-12-15 13:48

    PhantomJS is a better option for generating screenshot from URL. The following script demonstrates the simplest use of page capture. It loads the Github homepage and then saves it as an image, github.png. Code

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

    To run this example create a new file called github.js. Copy and paste the above code into the github.js file. In the commandline, run this newly created script with PhantomJS:

    phantomjs github.js
    

    There a lot of projects for generating screenshots using PhantomJS. Pageres generates reliable screenshots and its based on NodeJS and PhantomJS.

提交回复
热议问题