PhantomJS clearCookies()
clearCookies() 方法将删除指定页面的所有Cookie。
语法
其语法如下:
wpage.clearCookies();
示例
让我们看一个 clearCookies() 方法的示例。
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/a.html', function() {
console.log("Cookies available are :");
console.log(JSON.stringify(wpage.cookies));
console.log("Clearing all cookies");
wpage.clearCookies();
console.log("Cookies available now");
console.log(JSON.stringify(wpage.cookies));
phantom.exit();
});
上面的程序生成以下内容: 输出 。
Cookies available are :
[{"domain":".localhost","expires":"Sun, 07 May 2017 01:28:18 GMT","expiry":14941
00698,"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"}]
Clearing all cookies
Cookies available now
[]