PHP combines phantomjs to achieve webpage screenshots and grab JS rendering pages.
first PhantomJS fast introduction. It fully supports web without browser support, and its fast native support for various Web standards: DOM processing, CSS selector, JSON, Canvas, and SVG. PhantomJS can be used for page automation, network monitoring, web screenshots, and no interface testing.
1, install
install package download address: http://phantomjs.org/download.html, including Windows, versions, self selection of the corresponding release load Antomjs sets the environment variable, which contains a example folder, which contains many written code for use. This article assumes that phantomjs has been installed and environment variables have been set up.
two, use
Hello, World!
create a text file that contains the following two lines of script:
console.log ('Hello, world! ");
phantom.exit ();
save the file as hello.js, and then execute it:
the first line will print the string at the terminal. The second line phantom.exit will exit.
it is very important to call phantom.exit in this script, otherwise PhantomJS will not stop at all.
script parameter - how does Script Arguments
Phantomjs transfer parameters? As shown below:
phantomjs examples/arguments.js foo bar baz
foo, bar, Baz is the parameter to be passed. Br / >} else {
system.args.forEach (function (Arg, I) {
console.log (I ':' ARG);
page loading – page object, a web page by creating a web page Can be loaded, analyzed and rendered.