PhantomJS simple example_PHP tutorial

WBOY
Release: 2016-07-20 11:14:45
Original
1508 people have browsed it

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>
Copy after login

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440267.htmlTechArticlePhantomJS 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,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!