http://www.xinzimi.com/629.html
配置略去
1,打开淘宝登陆地址
2,点击提交按钮,出现验证码
3,截取验证码图片并进行保存
4,Java使用Ajax动态加载验证码图片
5,输入用户名,密码和验证码,提交表单,利用IO动态生成js文件
6,读取js文件内容,冰fill form 输入框
7,点击登陆按钮
8,登陆成功,等啥,down网页呗,然后IO读取解析网页。
总控制 js文件:
var casper = require('casper').create();
casper.start('https://login.taobao.com/member/login.jhtml?f=top&redirectURL=http://www.taobao.com/', function() {
// this.click('input[id="TPL_username"]');
//this.fill('input[id="TPL_username"]','[email protected]');
this.fill('form[id="J_StaticForm"]', {
'TPL_username': '[email protected]',
'TPL_password': 'xxxxxx'
}, false);
});
//casper.then(function() {
// this.click('input[id="J_SafeLoginCheck"]');
// this.capture("baidu1.png");
//this.echo('login...');
//});
casper.then(function() {
this.click('input[id="J_SubmitQuick"]');
// this.capture("baidu1.png");
this.echo('login...');
});
casper.then(function() {
this.click('id="J_StandardCode"');
// this.capture("baidu1.png");
this.echo('login...');
});
casper.then(function() {
// this.click('input[id="J_SubmitStatic"]');
this.wait(3000,function() {
this.capture("baidu99999.png");
});
});
casper.then(function() {
this.fill('form[id="J_StaticForm"]', {
'TPL_username': '[email protected]',
'TPL_password': 'xxxxxx',
'TPL_checkcode': 'sssrrrrr'
}, false);
});
casper.then(function() {
this.wait(3000,function() {
this.capture("baidunewnewnewnew.png");
});
});
casper.then(function() {
// this.click('input[id="J_SubmitStatic"]');
this.wait(30000,function() {
require('d:/pc/test3.js');
});
});
casper.then(function() {
// this.click('input[id="J_SubmitStatic"]');
this.wait(3000,function() {
this.capture("baiduok.png");
});
});
casper.then(function() {
this.click('button[class="J_Submit"]');
// this.capture("baidu1.png");
this.echo('login...');
});
casper.then(function() {
// this.click('input[id="J_SubmitStatic"]');
this.wait(3000,function() {
this.capture("baidu3333.png");
});
});
casper.then(function() {
this.wait(3000,function() {
this.capture("baidu4444.png");
});
});
casper.thenOpen('http://trade.taobao.com/trade/itemlist/list_bought_items.htm?spm=1.7274553.1997525045.2.VhoaDO', function (status) {
var url="http://trade.taobao.com/trade/itemlist/list_bought_items.htm?spm=1.7274553.1997525045.2.VhoaDO";
this.download(url, 'list.html');
});
casper.run();
动态生成配置文件:
casper.then(function() {
this.wait(30000,function() {
this.capture("baiduok.png");
});
});
casper.then(function() {
this.fill('form[id="J_StaticForm"]', {
'TPL_checkcode': 'sfv5'
}, false);
});
casper.then(function() {
this.wait(3000,function() {
this.capture("baiduok.png");
});
});