Phantomjs-deletecookie-method

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

PhantomJS-deleteCookie()

DeleteCookie()メソッドは、特定のページURLに存在する既存のCookieリストと一致する名前のCookieを削除するのに役立ちます。

構文

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

var wpage = require('webpage').create();
wpage.deleteCookie(cookiename);

次の例は、 deleteCookie メソッドの使用を示しています。

var wpage = require('webpage').create();
phantom.addCookie ({
   'name'     : 'cookie1',   /*mandatory property*/
   'value'    : '1234',      /*mandatory property*/
   'domain'   : 'localhost', /*mandatory property*/
   'path'     : '/',
   'httponly' : true,
   'secure'   : false,
   'expires'  : (new Date()).getTime() + (5000 *60* 60)
});

wpage.open('http://localhost/tasks/al', function() {
   console.log("Cookies available are :");
   console.log(JSON.stringify(wpage.cookies));
   wpage.deleteCookie('cookie1');
   console.log("Cookies available now after deleting cookie1");
   console.log(JSON.stringify(wpage.cookies));
   phantom.exit();
});

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

Cookies available are :
[{"domain":".localhost","expires":"Sun, 07 May 2017 10:21:04 GMT","expiry":14941
32664,"httponly":true,"name":"cookie1","path":"/","secure":false,"value":"1234" }
,{"domain":"localhost","expires":"Fri, 22 Dec 2017 12:00:00 GMT","expiry":151394
4000,"httponly":false,"name":"username","path":"/tasks/","secure":false,"value" :
"Roy"}]

Cookies available now after deleting cookie1
[{"domain":"localhost","expires":"Fri, 22 Dec 2017 12:00:00 GMT","expiry":151394
4000,"httponly":false,"name":"username","path":"/tasks/","secure":false,"value" :
"Roy"}]