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();
});
上述程序生成以下內容output。
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 []
相關用法
- PhantomJS onConsoleMessage()用法及代碼示例
- PhantomJS setContent()用法及代碼示例
- PhantomJS switchToFocusedFrame()用法及代碼示例
- PhantomJS onResourceRequested()用法及代碼示例
- PhantomJS onPageCreated()用法及代碼示例
- PhantomJS deleteCookie()用法及代碼示例
- PhantomJS renderBase64()用法及代碼示例
- PhantomJS onUrlChanged()用法及代碼示例
- PhantomJS onNavigationRequested()用法及代碼示例
- PhantomJS onAlert()用法及代碼示例
- PhantomJS onResourceError()用法及代碼示例
- PhantomJS evaluateJavascript()用法及代碼示例
注:本文由純淨天空篩選整理自 PhantomJS - clearCookies()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。