ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
PhantomJS的用处可谓非常广泛,诸如网络监测、网页截屏、无需浏览器的 Web 测试、页面访问自动化等 PhantomJS官方地址:[http://phantomjs.org/](http://phantomjs.org/)。   PhantomJS官方API:[http://phantomjs.org/api/](http://phantomjs.org/api/)。   PhantomJS官方示例:[https://phantomjs.org/examples.html](https://phantomjs.org/examples.html)   PhantomJS GitHub:[https://github.com/ariya/phantomjs/](https://github.com/ariya/phantomjs) [下载win版本](http://phantomjs.org/download.html)解压到d盘:D:\phantomjs-2.1.1-windows ![](https://img.kancloud.cn/7a/32/7a327b81c227d3e543834ab8d235246f_259x274.png) 将`D:\phantomjs-2.1.1-windows\bin`加入环境变量 win+R >>>cmd 测试全局环境变量是否配置成功: ``` phantomjs -v ``` ![](https://img.kancloud.cn/02/6b/026bcc77359565bf51569c266e4b433c_190x63.png) 必须cd到![](https://img.kancloud.cn/e9/df/e9dfccf2562fcc4670445a4e48fdead4_296x39.png) 执行 运行第一个官方例子: ``` phantomjs ../examples/arguments.js 1 2 ``` 效果: ![](https://img.kancloud.cn/ca/50/ca504ec604f052bdafd55a788c859754_648x103.png) 新建demo.js ``` var page = require('webpage').create(); page.open('http://example.com', function () { page.render('example.png'); phantom.exit(); }); ``` ![](https://img.kancloud.cn/57/bb/57bb48e4059c6d1e8f02f553d4287770_496x50.png) 在bin下生成了`http://example.com`页面图片,名为example.png ![](https://img.kancloud.cn/75/f0/75f0d043966ff2ac87a30e2f4b224b10_568x400.png)