-
Notifications
You must be signed in to change notification settings - Fork 0
/
lofter.js
77 lines (53 loc) · 1.48 KB
/
lofter.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
var casper = require('casper').create({
pageSettings: {
webSecurityEnabled: false
}
});
var fs = require('fs');
var i=0;
casper.start('http://www.lofter.com');
casper.then(function () {
this.capture("a0.png");
this.click('li.weixin a');
this.echo("using weixin...");
this.wait(3000);
});
casper.then(function() {
this.capture("a1.png");
});
casper.then(function() {
this.waitForSelector('li.user', function() {
this.thenOpen("http://www.lofter.com/tag/美臀/new", function() {
this.echo("open link...");
this.capture("a2.png");
});
var count = 15;
while(count>0){
this.then(function () {
this.scrollToBottom();
this.wait(10000);
});
count--;
}
this.then(function () {
var that = this;
var imgs = this.getElementsAttribute('.imgc img','src');
var content ="";
var today = new Date();
var todayStr =today.getFullYear()+"-"+today.getMonth()+"-"+today.getDate();
imgs.forEach(function(imgUrl){
if(imgUrl) {
content += imgUrl+"\r\n";
that.download(imgUrl, todayStr+'/'+i+'.jpg');
i++;
};
});
fs.write(todayStr+".txt", content, 'w');
this.echo("end...");
this.capture(++i+'.png');
});
}, function() {
this.echo("log in time out");
}, 300000);
});
casper.run()