2016-08-12 22 views
0

私はこれで私の頭を叩いています。CasperJSのスクリーンショットは空白の画面を表示します

私は、URLから画像をキャプチャし、それをファイルを保存しようとしているphantomjs 1.9.8

を使用してcasperjs 1.1.0-beta3の上で実行していますよ。

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(); 

私は "ブランク" 画面を取得しています:

は、これは私のコマンドです。 :-(

私は私のローカルシステム上で実行します。それは働く!私は私が間違っているのかわからないんだけど。

誰かがPINてくださいすることができ、私の問題を指す?

コンソールログ(とエラーログ):

[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'イベントに登録してください([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf#file) -2_caspererrors-js))。多分エラーがあるかもしれません。 –

+0

ありがとう@ArtjomB。私はそれを試してみましょう。 – TechnoCorner

+0

完全なデバッグログを見てください:https://justpaste.it/x8co @ArtjomB。 @ArtjomB。 – TechnoCorner

答えて

2

あなたのログが明らかにした理由なしで、空白の画面に責任があるかもしれない「エラー:例外TypeError 『未定義は、』() 『Object.assign.apply』を評価対象ではありません」 JavaScriptが実際に実行されました。

upgrade to PhantomJS 2.x(PhantomJS 1.xの背後のエンジンは現在5年以上経過している必要があります)またはポリフィルを追加する必要があります。私は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

関連する問題