PhantomJS plaintext属性

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标签。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程