- 文件系统模块
- 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
广告