2017-06-01 6 views
0

私は初心者で、最近casperjsでphantomjsを使い始めました。私はiframeから情報を取得したいが、phantomjsはそれをロードできない。Phantomjsはiframeを読み込めません

これは私のスクリプトです:

var casper = require('casper').create({ 
    verbose: true, 
    logLevel: "debug", 
    waitTimeout: 20000, 
    retryTimeout: 100, 
    viewportSize: { 
    width: 1920, 
    height: 1080 
    }, 
    pageSettings: { 
     "userAgent": 'Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1' 
    }, 
    localToRemoteUrlAccessEnabled: true 
}); 

casper.start(); 

casper.open('http://www.badboysbarber.ru/online'); 

casper.waitForSelector('.y-main-container', function() { 
    this.echo("Selector appeared."); 
}); 

casper.then(function() { 
    this.capture('screen.png'); 
}); 

casper.run(); 

(セレクタが正しく定義されているが)ので、ファントムは、エラーがスローされます。

[error] [phantom] Wait timeout of 20000ms expired, exiting. 

誰かが私を助けてくださいもらえますか?多分私は何か間違っているのですか?ありがとうございました。

答えて

0

iframeは、別のドキュメントの中にドキュメントをロードします。フレームで作業し、CasperJSを使用してデータを取得する場合は、おそらくwithFrame()Casper.prototypeにある必要があります。

次のスクリプトは、あなたのメインページの最初iframeの生のHTMLコンテンツをキャプチャ:あなたはwithFrame機能を使用していても

var casper = require('casper').create({ 
    viewportSize: { 
    width: 1920, 
    height: 1080 
    }, 
    pageSettings: { 
    'userAgent': 'Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1' 
    }, 
    localToRemoteUrlAccessEnabled: true 
}); 

casper.start('http://www.badboysbarber.ru/online'); 

casper.withFrame(0, function() { 
    this.echo(this.getHTML()); // HTML code of the first iframe 
}); 

casper.run(); 
+0

申し訳ありませんが、それはインラインフレームをロードするために失敗しました。 withFrame関数の中でthis.echo(this.getHTML());)の代わりにthis.captureSelector( 'selector.png'、 '.y-main-container');を使用してみてください。これが全体の問題です。 –

+0

さらに、[このトピック](https://groups.google.com/forum/#!topic/casperjs/AtbXjGnp7M0)も参照できます。 –

+0

もしあなたがHTMLコードを入手できれば、明らかに 'iframe'が読み込まれます。あなたはちょうど 'キャプチャ'の問題があります。私はSlimerJSで 'withFrame'の中で' this.capture( 'screenshot.png');を試しました。SlimerJSがページを処理しているときだけでなく、結果として得られるスクリーンショットでも 'iframe'を見ることができます:http:// imgur.com/a/gWtiY – Badacadabra

関連する問題