Home > Article > Backend Development > PhantomJS simple example_PHP tutorial
PhantomJS is an interfaceless browser with WebKit as the core and providing JavaScript programming interface (API). It provides fast and native support for web standards: DOM manipulation, CSS selectors, JSON, Canvas and SVG.
1. Download and decompress PhantomJS http://phantomjs.org/
2. Write a simple test code and save it as test.js. After decompression, there are a large number of examples under phantomjsexamples for reference
console.log('Loading a web page'<span ); </span><span var</span> page = require('webpage'<span ).create(); </span><span var</span> url = 'http://www.phantomjs.org/'<span ; page.open(url, </span><span function</span><span (status) { </span><span //</span><span Page is loaded!</span> <span if</span> (status !== 'success'<span ) { console.log(</span>'Unable to post!'<span ); } </span><span else</span><span { console.log(page.content); } phantom.exit(); });</span>
3. Because I am using windows, I enter the CMD command line mode to run test.js, and use the pipe character to output the results to test.txt. If no pipe is used, the results will be output directly.
.
4. Because PhantomJS supports the command line, we can use PHP, Java, or Python to directly obtain the results during the development process