PhantomJS - plaintext 属性
plainText 属性将网页内容作为纯文本返回,其中不包含任何 html 标签。
语法
其语法如下 −
wpage.plainText
示例
让我们举一个例子来了解 plainText 属性的用法。
var wpage = require('webpage').create();
wpage.open('http://localhost/tasks/a.html', function (status) {
console.log(wpage.plainText);
phantom.exit();
});
a.html
<html>
<head></head>
<body name = "a">
<script type = "text/javascript">
console.log('welcome to cookie example');
document.cookie = "username = Roy; expires = Thu, 22 Dec 2017 12:00:00 UTC";
window.onload = function() {
console.log("page is loaded");
}
</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>
上述程序生成以下输出。
This is a test page This is a test page This is a test page This is a test page This is a test page This is a test page This is a test page This is a test page This is a test page
plainText 属性仅返回不带任何脚本标签或 html 标签的内容。
phantomjs_webpage_module_properties.html

