- 檔案系統模組
- 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
廣告