PHANTOMJS Introduction-(JS Web screenshot, JavaScript page Parsing rendering tool)

Source: Internet
Author: User

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
  1. #[[email protected] bin]# cat Loading.js
  2. var page = require (' webpage '). Create (),
  3. Address, output, size;
  4. if (Phantom.args.length < 2 | | phantom.args.length > 3) {
  5. Console.log (' Usage:rasterize.js URL filename ');
  6. Phantom. exit ();
  7. } Else {
  8. address = phantom.args[0];
  9. output = phantom.args[1];
  10. Page.viewportsize = {width:1024, height:768};
  11. Page.open (Address, function (status) {
  12. if (status!== ' success ') {
  13. Console.log (' Unable to load the address! ');
  14. } Else {
  15. Window.settimeout (function () {
  16. Page.render (output);
  17. Phantom. exit ();
  18. }, 200);
  19. }
  20. });
  21. }


The current directory structure:

PHP code
    1. [[email protected] bin]# ls
    2. Loading.js PHANTOMJS

Execute script:

PHP code
    1. ./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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.