This repository was archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpacktpub_free_book.js
76 lines (64 loc) · 2.03 KB
/
packtpub_free_book.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
var username = "[email protected]";
var password = "password";
// ------------------------------------------------------------
var casper = require('casper').create({
clientScripts: [],
pageSettings: {
javascriptEnabled: true,
loadImages: false,
loadPlugins: false,
localToRemoteUrlAccessEnabled: true,
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)",
userName: null,
password: null,
XSSAuditingEnabled: false,
},
verbose: true,
logLevel: "debug",
});
var fs = require('fs');
var utils = require('utils');
var url, html, latest_book, json_book;
// print out all the messages in the headless browser context
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
});
// print out all the messages in the headless browser context
casper.on('error', function(msg, backtrace) {
this.echo("=========================");
this.echo("ERROR:");
this.echo(msg);
this.echo(backtrace);
this.echo("=========================");
});
casper.on("page.error", function(msg, backtrace) {
this.echo("=========================");
this.echo("PAGE.ERROR:");
this.echo(msg);
this.echo(backtrace);
this.echo("=========================");
});
casper.on('resource.requested', function(requestData, request) {
if ((/http(s?):\/\/.+?.css/gi).test(requestData['url']) || requestData['Content-Type'] == 'text/css') {
request.abort();
}
});
casper.start('https://www.packtpub.com', function() {
this.evaluate(function() {
$('#account-bar-form').show();
$('#account-bar-form-login').show();
});
});
casper.then(function() {
this.fill('#packt-user-login-form', {
email: username,
password: password,
}, true);
});
casper.thenOpen('https://www.packtpub.com/packt/offers/free-learning', function() {
url = this.evaluate(function() {
return 'https://www.packtpub.com' + $(".free-ebook a").attr('href');
});
casper.thenOpen(url);
});
casper.run();