0

Hi i am working with PhantomJs to capture screen from url. But it seem sresult not accurate.

version of PhantomJS : 1.9.8, Operating system : Ubuntu 14

With this below code i tried to capture screen from a url but it seems its not giving perfect screen shot.. Or i am doing something wrong ?

See on header part of this website and screen shot..both are not similar.

Result screen shot : http://www.awesomescreenshot.com/image/2275399/7cf995d2e287cb87c4ca4895b6b69934

Website which i am trying to capture: http://www.whiteboardexplainers.com/

var system = require("system");
if (system.args.length > 0) {
    var page = require('webpage').create();
    page.viewportSize = {width: 1280, height: 1024};
    page.open(system.args[1], function() {
        var pageTitle = system.args[1].replace(/http.*\/\//g, "").replace("www.", "").split("/")[0]
        var filePath = "pageTitle + '.png';

        window.setTimeout(function () {
            page.evaluate(function() {
                document.body.bgColor = 'white';
            });  
            page.render(filePath);
            console.log(filePath);
            phantom.exit();
        }, 200);

    });
}

1 Answers1

1

You use a very outdated PhantomJS version. Considering that, screnshot looks very good. Upgrade to a modern PhantomJS version: 2.1.1 or even better 2.5 beta. Get them here: PhantomJS downloads archive.

But even a modern version does not support showing videos, so that will not work anyway.

In your case it does not seem relevant but often is: it is advisable to declare a useragent string of a modern browser. Otherwise many sites show a mobile version of their pages.

Vaviloff
  • 16,282
  • 6
  • 48
  • 56
  • See on header part of this website and screen shot..both are not similar. –  Mar 09 '17 at 07:30
  • and what does it mean page.settings.userAgent = 'SpecialAgent'; Wht is special agent here.. we should pass any browser name or its ok with SpecialAgent ? –  Mar 09 '17 at 07:32
  • You can look your useragent on sites like this: http://www.whatsmyua.com/ or use any other sufficiently modern useragent string. – Vaviloff Mar 09 '17 at 07:44
  • Re: `not similar` - it's understandable that screenshots are not similar, because browsers themselves are different. 1.9.8 is rather old. – Vaviloff Mar 09 '17 at 07:46
  • thank you for you suggestion. but i used Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 and same issue .. –  Mar 09 '17 at 07:51
  • In this case usragent is not used by the remote site. What version PhantomJS is? – Vaviloff Mar 09 '17 at 07:55
  • version of PhantomJS : 1.9.8 –  Mar 09 '17 at 07:55
  • please try with a modern PhantomJS then – Vaviloff Mar 09 '17 at 08:24