- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- Web 伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 其他
- 命令列介面
- PhantomJS - 螢幕捕獲
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用資源
- PhantomJS - 快速指南
- PhantomJS - 有用資源
- PhantomJS - 討論
PhantomJS - openUrl()
openUrl 方法會開啟一個網頁。它類似於 phantomjs 的 open 方法。此方法有一些額外的引數,即 httpConf、settings 和 callback 函式。
HttpConf
HttpConf 是一個具有以下屬性的物件 −
Operation − 它是 HTTP 方法 GET/POST
Data − 它用於 POST 方法。
Headers − 一個類似於 wpage.customHeaders 的物件。
httpConf 的預設值是 get 方法。它是可選的,你可以為其指定 null。
Settings
它類似於 wpage.settings 屬性。如果你不想指定它,可以使用 null。
Callback
它會在頁面載入時呼叫。
語法
語法如下 −
wpage = openUrl(url, httpConf, settings);
示例
以下示例顯示了 openUrl() 方法的用法。
var wPage = require('webpage').create();
wPage.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
wPage.onLoadFinished = function(){
console.log('Entering on load finished');
console.log(wPage.content);
console.log(JSON.stringify(wPage.settings));
}
wPage.openUrl("https:///tasks/a.html","POST", wPage.settings);
上述程式生成以下 輸出。
Entering on load finished
<html>
<head>
<title>Welcome to phantomjs test page</title>
</head>
<body name = "a">
<script type = "text/javascsript">
window.onload = function() {
window.open("https:///tasks/alert.html", "t1");
}
</script>
<h1>This is a test page</h1>
<h1>This is a test page</h1>
<h1>This is a test page</h1>
<h1>This is a test page</h1>
<h1>This is a test page</h1>
<h1>This is a test page</h1>
<h1>This is a test page</h1>
<h1>This is a test page</h1>
<h1>This is a test page</h1>
</body>
</html>
{"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpen
Windows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccess
Enabled":false,"userAgent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36","webSecurityEnabled":true}
phantomjs_webpage_module_methods.htm
廣告