PhantomJS - plaintext Property



The plainText property returns the contents of the webpage as plain text without any html tags in it.

Syntax

Its syntax is as follows −

wpage.plainText 

Example

Let us take an example to understand the use of plainText property.

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> 

The above program generates the following output.

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

The plainText property just returns the contents without any script tags or html tags.

phantomjs_webpage_module_properties.htm
Advertisements