下载: [url]https://bitbucket.org/ariya/phantomjs/downloads[/url]
linux配置:
1. 配置
[b][color=darkblue]gedit .bash_profile[/color][/b]
--------------------------------
[color=darkblue]export PHANTOMJS_HOME=/mnt/D/OutsourcingServer/phantomjs
export CASPERJS_HOME=/mnt/D/OutsourcingServer/casperjs
PATH=..............:$PHANTOMJS_HOME/bin:$CASPERJS_HOME/bin[/color]
[color=darkblue][b]source .bash_profile[/b][/color] //使改变马上生效
测试:
[pandy@pandy-linux ~]$ [color=darkblue][b]phantomjs --version[/b][/color]
[color=red]1.9.2[/color]
[pandy@pandy-linux ~]$ [color=darkblue][b]casperjs --version[/b][/color]
[color=red]1.1.0-beta3[/color]
2.创建一个js: SaveChallengeMySelfService.js
3.到SaveChallengeMySelfService.js的位置执行:
[pandy@pandy-linux SandBag]$ [color=darkblue][b]casperjs SaveChallengeMySelfService.js[/b][/color]
后台输出: 打开百度, 截图完毕.
同时生成/mnt/D/OutsourcingServer/OutsourcingServerTest/src/main/webapp/SandBag/test.png图片。
linux配置:
1. 配置
[b][color=darkblue]gedit .bash_profile[/color][/b]
--------------------------------
[color=darkblue]export PHANTOMJS_HOME=/mnt/D/OutsourcingServer/phantomjs
export CASPERJS_HOME=/mnt/D/OutsourcingServer/casperjs
PATH=..............:$PHANTOMJS_HOME/bin:$CASPERJS_HOME/bin[/color]
[color=darkblue][b]source .bash_profile[/b][/color] //使改变马上生效
测试:
[pandy@pandy-linux ~]$ [color=darkblue][b]phantomjs --version[/b][/color]
[color=red]1.9.2[/color]
[pandy@pandy-linux ~]$ [color=darkblue][b]casperjs --version[/b][/color]
[color=red]1.1.0-beta3[/color]
2.创建一个js: SaveChallengeMySelfService.js
var casper = require('casper').create();
casper.start("http://www.baidu.com",function(){
this.capture("/mnt/D/OutsourcingServer/OutsourcingServerTest/src/main/webapp/SandBag/test.png",{
top: 00,
left: 0,
width: 1024,
height: 768
});
this.echo("打开百度, 截图完毕.");
});
casper.run();3.到SaveChallengeMySelfService.js的位置执行:
[pandy@pandy-linux SandBag]$ [color=darkblue][b]casperjs SaveChallengeMySelfService.js[/b][/color]
后台输出: 打开百度, 截图完毕.
同时生成/mnt/D/OutsourcingServer/OutsourcingServerTest/src/main/webapp/SandBag/test.png图片。
PhantomJS与CasperJS安装配置

本文介绍如何下载并配置PhantomJS与CasperJS环境,包括设置环境变量及通过CasperJS进行网页截图的基本操作。
645

被折叠的 条评论
为什么被折叠?



