- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- Web 伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 其他
- 命令列介面
- PhantomJS - 截圖
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用資源
- PhantomJS - 快速指南
- PhantomJS - 有用資源
- PhantomJS - 討論
PhantomJS - open()
open 方法用於開啟網頁。open 方法採用頁面 URL,並有一個回撥函式,在頁面載入時呼叫該函式。回撥函式是可選的,可根據需要使用。回撥函式包含的狀態用於定義頁面的成功或失敗。
語法
其語法如下所示 −
var wpage = require('webpage').create();
wpage.open(url, function(status) {
//status is success or failure
});
使用 GET 方法的 open()
var wpage = require('webpage').create();
wpage.open('http://www.google.com/', function(status) {
console.log(status);
phantom.exit();
});
上述程式生成以下輸出。
Success
使用 POST 方法的 open()
var wpage = require('webpage').create();
var postdata = "username = roy";
wpage.open('https:///tasks/a.php', 'POST',postdata, function(status) {
console.log(status);
console.log(wpage.content);
phantom.exit();
});
a.php
<?php print_r($_POST); ?>
上述程式生成以下輸出。
success <html><head></head><body>Array ( [username] => roy ) </body></html>
phantomjs_webpage_module_methods.htm
廣告