- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- Web 伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 雜項
- 命令列介面
- PhantomJS - 螢幕捕獲
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用資源
- PhantomJS - 快速指南
- PhantomJS - 有用資源
- PhantomJS - 討論
PhantomJS - deleteCookie()
DeleteCookie () 將有助於刪除一個 cookie,其名稱與給定頁面 URL 的現有 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('https:///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();
});
以上的程式生成以下 **輸出**。
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_webpage_module_methods.htm
廣告