Hello! It was required to do in screenshots of sites on pkhp. Installed on Ubuntu phantomjs.

I wrote the script:

system = require('system'); var url = system.args[1]; var filename = system.args[2]; var WebPage = require('webpage'); page = WebPage.create(); page.open(url); page.onLoadFinished = function() { page.render(filename + '.png'); phantom.exit(); } 

Call the script:

 phantomjs phantomsave.js https://www.yandex.ru 331 

Everything saves correctly. Calling for another site:

 phantomjs phantomsave.js https://www.google.ru 331 

It creates a picture weighing 1 kb. Is empty. And the main thing for the desired site is the same. What could be the problem?

  • Problem due to https sites. Http is correct. - Dmitriy
  • It turns out that for rendering https sites you need to call a script with ssl support example: phantomjs --ssl-protocol = any phantomsave.js google.ru 331. But now another problem. Half of the content on the page is not. Only the boundaries of the blocks without text and images. - Dmitriy

1 answer 1

According to the results of multiple experiments: wkhtmltoimage works many times more correctly. Bin in bin chmod + x and call.

 wkhtmltoimage --crop-h обрезка_по_высоте --javascript-delay время_ожидания_загрузки_ява_скрипт адрес_сайта имя_файла 

wkhtmltoimage