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/a.html', 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"}]
相关用法
- PhantomJS onConsoleMessage()用法及代码示例
- PhantomJS setContent()用法及代码示例
- PhantomJS switchToFocusedFrame()用法及代码示例
- PhantomJS onResourceRequested()用法及代码示例
- PhantomJS onPageCreated()用法及代码示例
- PhantomJS renderBase64()用法及代码示例
- PhantomJS onUrlChanged()用法及代码示例
- PhantomJS onNavigationRequested()用法及代码示例
- PhantomJS onAlert()用法及代码示例
- PhantomJS onResourceError()用法及代码示例
- PhantomJS evaluateJavascript()用法及代码示例
- PhantomJS includeJS()用法及代码示例
注:本文由纯净天空筛选整理自 PhantomJS - deleteCookie()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。