首先要安裝phantomjs 和 Casperjs, 具體安裝步驟:http://www.cnmiss.cn/?p=42ui
安裝好後運行一個簡單的例程:利用Casperjs +Phantomjs模擬登錄並截圖。this
代碼以下,具體參考:http://my.oschina.net/jiuxiaoyao/blog/148456spa
var casper = require('casper').create(); casper.start('https://passport.baidu.com/v2/?login', function() { this.fill('div[id="loginForm"]', { 'userName': 'whcyc2002', 'password': '*******' }, false); }); casper.then(function() { this.click('input[class="pass-button pass-button-submit"]'); this.echo('login...'); }); casper.then(function() { this.wait(3000,function() { this.capture("baidu.png"); }); }); casper.run();
Java外部引用能夠用 Apache Commons Exec.net
更多例程:
code
https://nicolas.perriault.net/code/2012/introducing-casperjs-toolkit-phantomjs/ orm
手冊:blog
http://docs.casperjs.org/en/latest/
ci