phantom_proxy 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/phantom_proxy/phantomjs.rb +6 -4
- data/lib/phantom_proxy/scripts/proxy.js +68 -86
- metadata +2 -2
@@ -75,10 +75,12 @@ module PhantomJSProxy
|
|
75
75
|
def invokePhantomJS(script, args)
|
76
76
|
argString = " "+args.join(" ")
|
77
77
|
puts("Call phantomJS with: "+argString)
|
78
|
-
out =
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
out = ""
|
79
|
+
IO.popen(PHANTOMJS_BIN+" --cookies-file=/tmp/phantom_proxy/cookies.txt "+script+argString) {|io|
|
80
|
+
out = io.readlines.join
|
81
|
+
}
|
82
|
+
puts("PHANTOMJS_OUT: "+out)
|
83
|
+
return out
|
82
84
|
end
|
83
85
|
end
|
84
86
|
end
|
@@ -23,12 +23,12 @@ function evaluateWithVars(page, func, vars)
|
|
23
23
|
function insertFrames(url) {
|
24
24
|
var page = require('webpage').create();
|
25
25
|
page.onConsoleMessage = function (msg) { console.log(msg); };
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
page.onAlert = function(msg) { console.log(msg);};
|
27
|
+
page.onLoadStarted = function () {
|
28
|
+
console.log('Start loading final Page...'+url);
|
29
29
|
};
|
30
30
|
page.open(url, function (status) {
|
31
|
-
|
31
|
+
if (status !== 'success') {
|
32
32
|
console.log('FAILED_LOADING_URL: '+url);
|
33
33
|
} else {
|
34
34
|
page.evaluate(function () {
|
@@ -47,7 +47,7 @@ function insertFrames(url) {
|
|
47
47
|
for (var i in frameContent) {
|
48
48
|
content = content.replace("PHANTOMJS_PROXY_IFRAME"+i, "<phantomjsframe>"+frameContent[i]+"</phantomjsframe>");
|
49
49
|
}
|
50
|
-
|
50
|
+
console.log("PHANTOMJS_DOMDATA_WRITE:"+content);
|
51
51
|
console.log('PHANTOMJS_DOMDATA_END');
|
52
52
|
}
|
53
53
|
console.log('WHATEVER');
|
@@ -56,21 +56,21 @@ function insertFrames(url) {
|
|
56
56
|
};
|
57
57
|
|
58
58
|
function exit() {
|
59
|
-
|
59
|
+
framesWorked++;
|
60
60
|
if (framesWorked == frameCount)
|
61
61
|
insertFrames(masterURL);
|
62
62
|
}
|
63
63
|
|
64
64
|
var loadpage = function(url) {
|
65
|
-
|
65
|
+
var page = require('webpage').create();
|
66
66
|
page.onConsoleMessage = function (msg) { console.log(msg); };
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
//page.onLoadFinished =
|
68
|
+
page.onAlert = function(msg) { console.log(msg);};
|
69
|
+
page.onLoadStarted = function () {
|
70
|
+
console.log('Start loading...'+url);
|
71
71
|
};
|
72
72
|
page.open(url, function (status) {
|
73
|
-
|
73
|
+
if (status !== 'success') {
|
74
74
|
console.log('FAILED_LOADING_URL: '+url);
|
75
75
|
} else {
|
76
76
|
console.log('LOADED PAGE CONTENT['+url+']\n');
|
@@ -78,25 +78,24 @@ var loadpage = function(url) {
|
|
78
78
|
}
|
79
79
|
console.log('WHATEVER');
|
80
80
|
exit();
|
81
|
-
|
81
|
+
});
|
82
82
|
};
|
83
83
|
|
84
84
|
function loadIFrames(page) {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
frameCount = frames.length+1;
|
85
|
+
var frames = page.evaluate(function () {
|
86
|
+
var framestmp = document.getElementsByTagName('IFRAME');
|
87
|
+
var frames = [];
|
88
|
+
for (var i=0;i<framestmp.length;i++) {
|
89
|
+
frames.push(framestmp[i].getAttribute('src'));
|
90
|
+
}
|
91
|
+
return frames;
|
92
|
+
});
|
93
|
+
|
94
|
+
for (var i=0;i<frames.length;i++) {
|
95
|
+
console.log("Frame: "+i+" : "+frames[i]);
|
96
|
+
loadpage(frames[i]);
|
97
|
+
}
|
98
|
+
frameCount = frames.length+1;
|
100
99
|
}
|
101
100
|
|
102
101
|
function main() {
|
@@ -105,64 +104,47 @@ function main() {
|
|
105
104
|
console.log('Usage: proxy.js <picture filename or none> <load iframe(true/false)> <URL> <url param count> <url params...>');
|
106
105
|
phantom.exit();
|
107
106
|
} else {
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
for (var i=0;i<frames.length;i++) {
|
150
|
-
|
151
|
-
console.log("Frame: "+i+" : "+frames[i]);
|
152
|
-
loadpage(frames[i]);
|
153
|
-
}
|
154
|
-
frameCount = frames.length+1;
|
155
|
-
*/
|
156
|
-
}
|
157
|
-
//evaluateWithVars(page, function(){}, phantom.args);
|
158
|
-
console.log('PHANTOMJS_MAINDOM_WRITE:'+page.content);
|
159
|
-
console.log('PHANTOMJS_MAINDOM_END');
|
160
|
-
}
|
161
|
-
if (file_name != null && file_name != "none") {
|
162
|
-
page.render(file_name);
|
163
|
-
}
|
164
|
-
exit();
|
165
|
-
});
|
107
|
+
file_name = phantom.args[0];
|
108
|
+
var loadIframes = phantom.args[1].match(/true/i) ? true : false;
|
109
|
+
address = phantom.args[2];
|
110
|
+
|
111
|
+
var argCount = phantom.args[3];
|
112
|
+
|
113
|
+
args = ""
|
114
|
+
|
115
|
+
for (var i=0;i<argCount;i++)
|
116
|
+
args += phantom.args[i+4]+'&';
|
117
|
+
if (args.length > 0)
|
118
|
+
address += '?'+args;
|
119
|
+
|
120
|
+
console.log("Open page: "+address+", "+args+" END");
|
121
|
+
|
122
|
+
var page = require('webpage').create();
|
123
|
+
|
124
|
+
page.onConsoleMessage = function (msg) { console.log(msg); };
|
125
|
+
|
126
|
+
console.log('start openning page');
|
127
|
+
|
128
|
+
masterURL = address;
|
129
|
+
|
130
|
+
page.open(address, function (status) {
|
131
|
+
if (status !== 'success') {
|
132
|
+
console.log('FAILED_LOADING_URL');
|
133
|
+
} else {
|
134
|
+
console.log('DONE_LOADING_URL');
|
135
|
+
//load iframes into page
|
136
|
+
if (loadIframes) {
|
137
|
+
loadIFrames(page);
|
138
|
+
}
|
139
|
+
//evaluateWithVars(page, function(){}, phantom.args);
|
140
|
+
console.log('PHANTOMJS_MAINDOM_WRITE:'+page.content);
|
141
|
+
console.log('PHANTOMJS_MAINDOM_END');
|
142
|
+
}
|
143
|
+
if (file_name != null && file_name != "none") {
|
144
|
+
page.render(file_name);
|
145
|
+
}
|
146
|
+
exit();
|
147
|
+
});
|
166
148
|
}
|
167
149
|
}
|
168
150
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantom_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|