PHANTOMJS Introduction-(JS Web screenshot, JavaScript page Parsing rendering tool)
Phantomjs is a JS-based WebKit kernel Headless browser is not the display interface of the browser, so access to the Web page eliminates the browser's interface to draw the system resources consumed, more suitable for network testing and other applications. With this tool, we can easily build an interface to get a full page screenshot of the URL we want.
Phantomjs is a headless WebKit with JavaScript API. It has fast and native support for various web standards:dom handling, CSS selector, JSON, Canvas, and SVG.
PHANTOMJS is created by Ariya Hidayat.
Official website: http://phantomjs.org/
Use the Tutorial:
First to download the latest version of PHANTOMJS on its official website, the latest version is now 1.7.
Write a loading.js to the same directory:
PHP code
- #[[email protected] bin]# cat Loading.js
- var page = require (' webpage '). Create (),
- Address, output, size;
- if (Phantom.args.length < 2 | | phantom.args.length > 3) {
- Console.log (' Usage:rasterize.js URL filename ');
- Phantom. exit ();
- } Else {
- address = phantom.args[0];
- output = phantom.args[1];
- Page.viewportsize = {width:1024, height:768};
- Page.open (Address, function (status) {
- if (status!== ' success ') {
- Console.log (' Unable to load the address! ');
- } Else {
- Window.settimeout (function () {
- Page.render (output);
- Phantom. exit ();
- }, 200);
- }
- });
- }
The current directory structure:
PHP code
- [[email protected] bin]# ls
- Loading.js PHANTOMJS
Execute script:
PHP code
- ./PHANTOMJS loading.js http://weibo.com./weibo.png
The third parameter is the URL that needs to be intercepted, and the fourth parameter is where the captured picture is stored.
How to use PHANTOMJS to do Web page parsing rendering tool.
PHANTOMJS Introduction-(JS Web screenshot, JavaScript page Parsing rendering tool)