Phantomjs-onresourcereceived

提供:Dev Guides
移動先:案内検索

PhantomJS-onResourceReceived()

このコールバックは、ページによって要求されたリソースが受信されたときに呼び出されます。 引数として応答が含まれます。

応答オブジェクトには次の詳細があります-

  • Id -要求されたリソースの番号。
  • URL -要求されたURL。
  • 時間-応答の日付を含む日付オブジェクト。
  • ヘッダー-HTTPヘッダー。
  • BodySize -解凍された受信コンテンツのサイズ。
  • ContentType -指定されている場合、コンテンツタイプ。
  • RedirectURL -リダイレクトがある場合は、リダイレクトされたURL。
  • ステージ-値は–開始と終了です。
  • ステータス-HTTPコードのステータス、すなわち ステータス200。
  • StatusText -コード200のHTTPステータステキスト、OKです。

構文

その構文は次のとおりです-

page.onResourceReceived = function(response) {}

次のコードは、* onResourceReceived()*メソッドの使用を示しています。

var wpage = require('webpage').create();
wpage.onResourceReceived = function(response) {
   console.log(JSON.stringify(response));
}
wpage.open('http://localhost/tasks/promptl', function(status) {
});

上記のプログラムは、次の output を生成します。

{"body":"","bodySize":231,"contentType":"text/html","headers":[{"name":"Date",
"value":"Sun, 07 May 2017 12:59:17 GMT"},{"name":"Server","value":"Apache/2.4.17
(Win32) OpenSSL/1.0.2d PHP/5.6.23"},{"name":"Last-Modified","value":"Sun,
07 May 2017 12:48:14 GMT"},{"name":"ETag","value":"\"e754eee893517e5\""},
{"name":"Accept-Ranges","value":"bytes"},{"name":"ContentLength","value":"231"},
{"name":"Keep-Alive","value":"timeout=5, max=100"},{"name":"Connection","value":
"Keep-Alive"},{"name":"ContentType","value":"text/html"}],"id":1,"redirectURL":null,
"stage":"start","status": 200,"statusText":"OK","time":"2017-05-07T12:59:17.440Z",
"url": "http://localhost/tasks/promptl"}

{"contentType":"text/html","headers":[{"name":"Date","value":"Sun,
07 May 2017 12:59:17 GMT"},{"name":"Server","value":"Apache/2.4.17
(Win32) OpenSSL/1.0.2d PHP/5.6.23"},{"name":"Last-Modified","value":
"Sun, 07 May 2017 12:48:14 GMT"},{"name":"ETag","value":"\"e7-54eee893517e5\""},
{"name":"AcceptRanges","value":"bytes"},{"name":"Content-Length","value":"231"},
{"name":"KeepAlive","value":"timeout=5, max=100"},{"name":"Connection",
"value":"KeepAlive"},{"name":"Content-Type", "value":"text/html"}],
"id":1,"redirectURL":null,"stage":"end","status":200,"statusText":"OK",
"time":"2017-0507T12:59:17.486Z","url":"http://localhost/tasks/promptl"}