This repository was archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathload.js
More file actions
121 lines (92 loc) · 2.66 KB
/
load.js
File metadata and controls
121 lines (92 loc) · 2.66 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// call this script like
// phantomjs load.js http://website outputPath zoom
console.log("Start phantomjs");
var scroll = 400;
var page = require('webpage').create();
var system = require('system');
var address = system.args[1];
var save = system.args[2];
var zoom = system.args[3];
console.log("Website : " + address);
console.log("Save path : " + save);
page.zoomFactor = zoom;
page.open(address, function(status) {
if (status === "success")
{
page.injectJs("injectme.js")
// being the actual size of the headless browser
page.viewportSize = { width: 1280, height: 720 };
var height = page.evaluate(function() { return document.body.offsetHeight });
var act = 0;
var urlIndex = 0;
var d = new Date();
var n = d.getTime();
height = parseInt(height * page.zoomFactor);
console.log("page =" + height);
while (act < height)
{
console.log(act);
page.clipRect = {
top: act,
left: 0,
width: 1280,
height: 720
};
if(urlIndex > 99)
{
getFilename = save + "t" + n + "_" + urlIndex + ".jpg";
}
else if(urlIndex > 9)
{
getFilename = save + "t" + n + "_0" + urlIndex + ".jpg";
}
else
{
getFilename = save + "t" + n + "_00" + urlIndex + ".jpg";
};
page.render(getFilename);
// zoom ?
if(zoom != 1)
{
// workarround for zoom not working !
if(parseInt(urlIndex) & 1)
{
page.zoomFactor = zoom;
}
else
{
page.zoomFactor = zoom - 0.01;
}
}
urlIndex++;
act = act + scroll;
};
};
var fs = require('fs');
fs.write(save + 'page.html', page.content, 'w');
});
page.onLoadFinished = function(status){
console.log('Status: ' + status);
console.log('Starting evaluate links...');
var txt = "";
var links = page.evaluate(function() {
return [].map.call(document.querySelectorAll('a'), function(link) {
var ht = link.getAttribute('href');
var no = link.getAttribute('ml_link');
if(ht != null)
{
return ht + " [_" + no + "_]";
}
else
return null;
});
});
txt = links.join('\n');
var fs = require('fs');
try {
fs.write(save + "links.txt", txt, 'w');
} catch(e) {
console.log(e);
}
phantom.exit(0);
}