- PhantomJS Tutorial
- PhantomJS - Home
- PhantomJS - Overview
- PhantomJS - Environment Setup
- PhantomJS - Object
- PhantomJS - Methods
- WebPage Module
- PhantomJS - Properties
- PhantomJS - Methods
- PhantomJS - Events/Callbacks
- PhantomJS - Child Process Module
- File System Module
- PhantomJS - Properties
- PhantomJS - Methods
- System Module
- PhantomJS - Properties
- Web Server Module
- PhantomJS - Properties
- PhantomJS - Methods
- Miscellaneous
- Command Line Interface
- PhantomJS - Screen Capture
- PhantomJS - Page Automation
- PhantomJS - Network Monitoring
- PhantomJS - Testing
- PhantomJS - REPL
- PhantomJS - Examples
- PhantomJS Useful Resources
- PhantomJS - Quick Guide
- PhantomJS - Useful Resources
- PhantomJS - Discussion
PhantomJS - content Property
This property contains the contents of a webpage.
Syntax
Its syntax is as follows −
var page = require('webpage').create(); page.content;
To show an example let us open up a page and console and see what we get in page.content.
The open webpage method in detail will be discussed later. Right now, we will use it to explain the properties with it.
Example
The following example shows how you can use the content property.
var wpage = require('webpage').create(),url = 'http://localhost/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(); } });
The above program generates the following output.
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>
Here, we will use the local page to fetch the contents and the output of the page that is shown above. The page.content function works just like the view source function of the browser.
phantomjs_webpage_module_properties.htm
Advertisements
To Continue Learning Please Login
Login with Google