Install Phantomjs + Casperjs
Casperjs is a navigation test script and development tool written in JavaScript. This article mainly describes how to install and use Casperjs in windows. If you have just heard of Casperjs, go to the introduction section of CasperJS to learn about the functions and functions of Casperjs, and then come back to learn how to install CasperJS.
CasperJS is based on PhantomJS. Therefore, you must install PhantomJS before installing CasperJS. Download PhantomJS here. For windows installation, download the windows version.
Step 1: Download PhantomJS, decompress the folder in the compressed package to drive D, rename the folder to phantomjs, and add the environment variable in windows; D: \ phantomjs to Path. Here, you do not need to care about the content in the phantomjs folder.
Step 2: Next we will download CasperJS. Click here to download the version is 1.1-beta3.
Step 3: Download CasperJS, decompress the folder in the compressed package to drive D, rename the folder to casperjs, and add the environment variable in windows; D: \ casperjs \ bin to Path.
Step 4: run the cmd command in the running state to open the console and run the command> casperjs-version. If you can print the published document number, congratulations, CasperJS has been installed successfully.
PhantomJS implements website screenshots
2. phantomjs application scenarios
Web regression testing
Webpage Screenshot, png, pdf
Network condition monitoring
3. phantomjs webpage screenshot
1. Download phantomjs Windows:
Http://phantomjs.org/download.html
2. Decompress the package and obtain the following files:
3. Right-click a file and name it snap. js. Enter the following content:
The code is as follows: |
Copy code |
Var page = new WebPage (), 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: 600, height: 600 }; 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 ); } }); } |
4. Choose start> Search> CMD to enable the command line mode:
5. Locate your phantomjs Directory, enter the following code, and press enter to get the following running Status:
Phantom js snap. js http://www.google.com.sg google.png
6. Get the screenshot.
Chinese website screenshot garbled, font installation solution
The website that uses phantomjs to capture Chinese pages may be garbled, that is, the Chinese position in the screenshot is a box.
The solution is to install the font.
Run yum install bitmap-fonts-cjk in centos.
Run sudo apt-get install xfonts-wqy in ubuntu.
In this way, a bunch of boxes will not appear on the Chinese page.