Guest User

Untitled

a guest
Feb 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. var page = require('webpage').create();
  2. var args = require('system').args;
  3.  
  4. var output_file = 'example.png', url = args[1];
  5. t = Date.now();
  6.  
  7. var width = 1440;
  8. var height = 900;
  9. page.viewportSize = { width: width, height: height };
  10. page.paperSize = {
  11. format: 'A4',
  12. orientation: 'landscape',
  13. margin: { left: '1cm', right: '1cm', top: '1cm', bottom: '1cm' }
  14. };
  15.  
  16. console.log(url);
  17.  
  18. page.onConsoleMessage = function(msg, lineNum, sourceId) {
  19. console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
  20. };
  21.  
  22. page.onLoadFinished = function (status) {
  23. window.setTimeout(function () {
  24. try {
  25. page.evaluate(function (w, h) {
  26. document.body.style.width = w + 'px';
  27. document.body.style.height = h + 'px';
  28. }, width, height);
  29. t = Date.now() - t;
  30. console.log('Loading ' + url);
  31. console.log('Loading time ' + t + ' msec');
  32. page.clipRect = {top: 0, left: 0, width: width, height: height};
  33. page.render(output_file);
  34. }
  35. catch (e) {
  36. status = e.message;
  37. }
  38. console.log(status + ';;' + output_file);
  39. phantom.exit();
  40. }, 10000);
  41. };
  42.  
  43. try {
  44. page.open(url);
  45. console.log('loading');
  46. }
  47. catch (ex) {
  48. console.log(ex.message);
  49. phantom.exit();
  50. }
  51.  
  52. page.onInitialized = function() {
  53. if(page.injectJs('core.js')){
  54. console.log("Polyfills loaded");
  55. }
  56. }
  57.  
  58. page.onInitialized = function() {
  59. if(page.injectJs('core.js')){
  60. console.log("Polyfills loaded");
  61. }
  62. }
Add Comment
Please, Sign In to add comment