- 文件系统模块
- PhantomJS - 属性
- PhantomJS - 方法
- 系统模块
- PhantomJS - 属性
- Web 服务器模块
- PhantomJS - 属性
- PhantomJS - 方法
- 杂项
- 命令行界面
- PhantomJS - 屏幕捕获
- PhantomJS - 页面自动化
- PhantomJS - 网络监控
- PhantomJS - 测试
- PhantomJS - REPL
- PhantomJS - 示例
- 有用的 PhantomJS 资源
- PhantomJS - 快速指南
- 有用的 PhantomJS 资源
- PhantomJS - 讨论
PhantomJS - 内容属性
此属性包含网页的内容。
语法
其语法如下 −
var page = require('webpage').create();
page.content;
下面我们打开一个页面和控制台来演示 page.content 中显示的内容。
关于 打开网页方法 的详细信息,后面会讨论。现在,我们使用该方法来说明这种属性。
示例
以下示例演示如何使用 content 属性。
var wpage = require('webpage').create(),url = 'https:///tasks/a.html';
wpage.open(url, function(status) {
if (status) {
console.log(status);
var content = wpage.content;
console.log('Content: ' + content);
phantom.exit();
} else {
console.log("could not open the file");
phantom.exit();
}
});
以上程序生成以下 输出。
Success
Content: <html>
<head></head>
<body>
<script type = "text/javascript">
console.log('welcome to cookie example');
document.cookie = "username = Roy; expires = Thu, 22 Dec 2017 12:00:00 UTC";
</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>
这里,我们将使用本地页面来获取内容以及上方显示的页面输出。page.content 函数的工作方式恰如浏览器的 查看源代码 功能。
phantomjs_webpage_module_properties.htm
广告