-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
92 lines (84 loc) · 2.35 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//phantom.outputEncoding = "GBK";
var initUrl = 'http://www.zhaopin.com/';
var casper = require('casper').create({
stepTimeout: 30000,
clientScripts: ["jquery.js"],
verbose: true,
pageSettings: {
javascriptEnabled: true,
//userAgent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
loadImages: true
},
onError: function (self, m) {
console.log("onError===================:" + m);
self.exit(1);
}
// onResourceReceived:function (result) {//当请求资源加载完成
// console.log("==============result========="+result)
// }
// logLevel: "debug",
}).start();
// casper.page.onPageCreated = function (newPage) {
// newPage.customHeaders = {
// "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"
// };
// };
casper.on('remote.message', function (msg) {
if (msg.indexOf(">>>>") == 0) {
var _msg = msg.replace(">>>>", "");
this.echo(_msg, 'info');
}
});
//打印输出
function log(txt) {
console.log(">>>>" + txt);
}
var option = {
method: 'GET',
timeout: 30000,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
};
/*打印title*/
casper.thenOpen(initUrl, option, function () {
log("StartUrl===" + this.getCurrentUrl());
log("StartTitle===" + this.getTitle());
});
/*输入用户名密码*/
casper.wait(2000,function () {
this.fill('div[id="loginU"]', {
'loginname': '',
'Password': ''
}, true);
casper.capture('1111.png');
});
/*等待资源被加载完成*/
// casper.on('resource.received', function (resource) {
// this.fill('div[id="loginU"]', {
// 'loginname': '',
// 'Password': ''
// }, true);
// console.log(resource.url)
// casper.capture('1111.png');
// });
/*提交表单*/
casper.then(function () {
this.evaluate(function () {
document.forms[0].submit();
});
});
/*关闭弹窗*/
casper.wait(2000,function () {
this.click(".popup_close");
casper.capture('2222.png');
});
casper.wait(2000,function () {
this.clickLabel("刷新");
});
casper.wait(2000,function () {
casper.capture('3333.png');
console.log("程序结束");
this.exit(1);
});
casper.run();