2016-08-12 2 views
0

나는 이걸로 머리를 치고 있었다.CasperJS 스크린 샷은 빈 화면을 낸다.

가 나는 URL에서 이미지를 캡처하고 그것을 파일을 저장하기 위해 노력하고있어 phantomjs 1.9.8

를 사용 casperjs에 1.1.0-베타 3를 실행하고 있습니다.

casperjs --proxy-type=none --ssl-protocol=any /home/casper-capture.js http://url.com/demo/demo /home/demoScreenshot.png 

이것은 내 캐스퍼 - capture.js

/** 
* capture image from url and save it to file. 
**/ 
var casper = require('casper').create({ 
    verbose: true, 
    logLevel: "debug", 
    viewportSize: { 
     width: 2300, 
     height: 1200 
    }, 
    pageSettings: { 
     webSecurityEnabled: false, 
     loadImages: true,  // The WebPage instance used by Casper will 
     loadPlugins: true   // use these settings 
    } 
}); 
// delay before image capturing 
var delay = 60000; 
//timeout delay for loading 
var timeoutForLoading = 10 * 60000; 
// image source url. 
var url = casper.cli.args[0]; 
// image output path 
var path = casper.cli.args[1]; 

casper.start().zoom(4).thenOpen(url, function urlCaptureClouser() { 
    this.wait(delay, function(){ 
     casper.waitFor(function check() { 
      return this.evaluate(function() { 
       return document.querySelectorAll('.fa-spin').length + 
         document.querySelectorAll('.chart-loading').length == 0; 
      }); 
     }, function then() { 
      this.capture(path); 
     }, function then() { 
      this.capture(path); 
     }, timeoutForLoading); 
    }); 
}); 

casper.run(); 

나는 "빈"화면납니다 :

이 내 명령입니다. :-(

내 로컬 시스템에서 실행

. 그것은 내가 잘못 뭐하는 거지 모르겠어요! 작동합니다.

누군가가 내 문제를 지적 핀시겠습니까?

콘솔 로그 (와 오류 로깅) :

[info] [phantom] Starting... 
[info] [phantom] Running suite: 2 steps 
[debug] [phantom] opening url: <URL>, HTTP GET 
[debug] [phantom] Navigation requested: url=<URL>, type=Other, willNavigate=true, isMainFrame=true 
[debug] [phantom] url changed to "<URL>" 
Error: TypeError: 'undefined' is not an object (evaluating 'Object.assign.apply') 
[debug] [phantom] Successfully injected Casper client-side utilities 
[info] [phantom] Step urlCaptureClouser 2/2 <URL> (HTTP 200) 
[info] [phantom] Step urlCaptureClouser 2/2: done in 329ms. 
[info] [phantom] Step _step 3/3 <URL> (HTTP 200) 
[info] [phantom] Step _step 3/3: done in 351ms. 
[info] [phantom] wait() finished waiting for 60000ms. 
[info] [phantom] Step _step 4/4 <URL> (HTTP 200) 
[info] [phantom] Step _step 4/4: done in 60358ms. 
[info] [phantom] waitFor() finished in 41ms. 
[info] [phantom] Step then 5/5 <URL> (HTTP 200) 
[debug] [phantom] Capturing page to /home/dmeo1991.png 
[info] [phantom] Capture saved to /home/dmeo1991.png 
[info] [phantom] Step then 5/5: done in 60674ms. 
[info] [phantom] Done 5 steps in 60674ms 
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match. 
+0

PhantomJS 및 CasperJS는 어떻게 설치 했습니까? NPM을 통해 했습니까? 'resource.error','page.error','remote.message' 및'casper.page.onResourceTimeout' 이벤트에 등록하십시오 ([예제] (https://gist.github.com/artjomb/4cf43d16ce50d8674fdf#file). -2_caspererrors-js)). 어쩌면 오류가있을 수 있습니다. –

+0

@ArtjomB 감사합니다. 저것을 시도하게하십시오. – TechnoCorner

+0

전체 디버그 로그를 확인하십시오 : https://justpaste.it/x8co @ArtjomB. – TechnoCorner

답변

2

로그 밝혀 때문에 없음의 빈 화면에 대한 책임 수있는 "오류 : 형식 오류 '정의되지 않은이'() 'Object.assign.apply'을 평가하는 객체가 아닌" JavaScript가 실제로 실행되었습니다.

upgrade to PhantomJS 2.x (PhantomJS 1.x의 엔진은 현재 5 년 이상 경과)이거나 polyfill을 추가해야합니다. MDN에서 polyfill을 복사했습니다.

casper.on('page.initialized', function(){ 
    this.evaluate(function(){ 
     // Polyfill... 
     if (typeof Object.assign != 'function') { 
      Object.assign = function(target) { 
      'use strict'; 
      if (target == null) { 
       throw new TypeError('Cannot convert undefined or null to object'); 
      } 

      target = Object(target); 
      for (var index = 1; index < arguments.length; index++) { 
       var source = arguments[index]; 
       if (source != null) { 
       for (var key in source) { 
        if (Object.prototype.hasOwnProperty.call(source, key)) { 
        target[key] = source[key]; 
        } 
       } 
       } 
      } 
      return target; 
      }; 
     } 
    }); 
}); 

casper.start(...)... 
+0

정말 고마워요 !!!! 이것은 매력처럼 일했습니다! – TechnoCorner