phantom_proxy 1.2.8 → 1.2.9
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 +7 -7
- data/lib/phantom_proxy/scripts/proxy.js +22 -14
- metadata +4 -4
@@ -4,15 +4,15 @@ module PhantomJSProxy
|
|
4
4
|
class PhantomJS
|
5
5
|
attr_accessor :dom
|
6
6
|
attr_accessor :image
|
7
|
-
|
7
|
+
attr_accessor :ready
|
8
8
|
|
9
9
|
def initialize()
|
10
|
-
@ready =
|
10
|
+
@ready = 503
|
11
11
|
end
|
12
12
|
|
13
13
|
def getUrl(url, pictureOnly=true, loadIFrames=true)
|
14
14
|
puts("PhantomJS: "+url)
|
15
|
-
@ready =
|
15
|
+
@ready = 503
|
16
16
|
|
17
17
|
pictureFile = nil
|
18
18
|
picture = "none"
|
@@ -65,7 +65,7 @@ module PhantomJSProxy
|
|
65
65
|
end
|
66
66
|
@ready = 200
|
67
67
|
end
|
68
|
-
if /
|
68
|
+
if /URL_ERROR_CODE/.match(@dom)
|
69
69
|
puts("LOAD_ERROR_CODE")
|
70
70
|
@ready = getHTTPCode @dom
|
71
71
|
puts("LOAD_ERROR_CODE_DONE")
|
@@ -81,8 +81,8 @@ module PhantomJSProxy
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def getHTTPCode data
|
84
|
-
tmp = data.split('
|
85
|
-
tmp = tmp.split('
|
84
|
+
tmp = data.split('URL_ERROR_CODE: ')[1];
|
85
|
+
tmp = tmp.split('URL_ERROR_CODE_END')[0]
|
86
86
|
#tmp = /FAILED_LOADING_URL: (.*?)FAILED_LOADING_URL_END/.match(data)[1]
|
87
87
|
tmp.to_i
|
88
88
|
end
|
@@ -95,7 +95,7 @@ module PhantomJSProxy
|
|
95
95
|
argString = " "+args.join(" ")
|
96
96
|
puts("Call phantomJS with: "+argString)
|
97
97
|
out = ""
|
98
|
-
IO.popen(PHANTOMJS_BIN+" --cookies-file=/tmp/phantom_proxy/cookies.txt "+script+argString) {|io|
|
98
|
+
IO.popen(PHANTOMJS_BIN+" --cookies-file=/tmp/phantom_proxy/cookies.txt --ignore-ssl-errors=yes "+script+argString) {|io|
|
99
99
|
out = io.readlines.join
|
100
100
|
}
|
101
101
|
#puts("PHANTOMJS_OUT: "+out)
|
@@ -4,6 +4,7 @@ var framesWorked = 0;
|
|
4
4
|
var frameCount = 1;
|
5
5
|
var frameContent = [];
|
6
6
|
var masterURL = "";
|
7
|
+
var masterPage = null;
|
7
8
|
|
8
9
|
function evaluateWithVars(page, func, vars)
|
9
10
|
{
|
@@ -21,6 +22,9 @@ function evaluateWithVars(page, func, vars)
|
|
21
22
|
}
|
22
23
|
|
23
24
|
function insertFrames(url) {
|
25
|
+
|
26
|
+
var page = masterPage;
|
27
|
+
/*
|
24
28
|
var page = require('webpage').create();
|
25
29
|
page.onConsoleMessage = function (msg) { console.log(msg); };
|
26
30
|
page.onAlert = function(msg) { console.log(msg);};
|
@@ -30,7 +34,7 @@ function insertFrames(url) {
|
|
30
34
|
page.open(url, function (status) {
|
31
35
|
if (status !== 'success') {
|
32
36
|
console.log('FAILED_LOADING_URL: '+url);
|
33
|
-
} else {
|
37
|
+
} else {*/
|
34
38
|
page.evaluate(function () {
|
35
39
|
var framestmp = document.getElementsByTagName('IFRAME');
|
36
40
|
var frames = []
|
@@ -41,18 +45,19 @@ function insertFrames(url) {
|
|
41
45
|
for (var i in frames) {
|
42
46
|
frames[i].innerHTML = "PHANTOMJS_PROXY_IFRAME"+i;
|
43
47
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
});
|
49
|
+
|
50
|
+
//replace iframes with their data
|
51
|
+
var content = new String(page.content);
|
52
|
+
for (var i in frameContent) {
|
53
|
+
content = content.replace("PHANTOMJS_PROXY_IFRAME"+i, "<phantomjsframe>"+frameContent[i]+"</phantomjsframe>");
|
54
|
+
}
|
55
|
+
console.log("PHANTOMJS_DOMDATA_WRITE:"+content);
|
56
|
+
console.log('PHANTOMJS_DOMDATA_END');
|
57
|
+
//}
|
53
58
|
console.log('WHATEVER');
|
54
59
|
phantom.exit();
|
55
|
-
});
|
60
|
+
//});
|
56
61
|
};
|
57
62
|
|
58
63
|
function exit() {
|
@@ -91,11 +96,12 @@ function loadIFrames(page) {
|
|
91
96
|
return frames;
|
92
97
|
});
|
93
98
|
|
99
|
+
frameCount = frames.length+1;
|
100
|
+
|
94
101
|
for (var i=0;i<frames.length;i++) {
|
95
102
|
console.log("Frame: "+i+" : "+frames[i]);
|
96
103
|
loadpage(frames[i]);
|
97
104
|
}
|
98
|
-
frameCount = frames.length+1;
|
99
105
|
}
|
100
106
|
|
101
107
|
function main() {
|
@@ -127,17 +133,19 @@ function main() {
|
|
127
133
|
|
128
134
|
masterURL = address;
|
129
135
|
|
136
|
+
masterPage = page;
|
137
|
+
|
130
138
|
//catches status != 200 and throws error immidiatly
|
131
139
|
page.onResourceReceived = function (response) {
|
132
140
|
if (response.stage == "end" && response.url == address && response.status != 200)
|
133
141
|
{
|
134
|
-
console.log('
|
142
|
+
console.log('URL_ERROR_CODE: '+response.status+'URL_ERROR_CODE_END');
|
135
143
|
//phantom.exit();
|
136
144
|
}
|
137
145
|
};
|
138
146
|
|
139
147
|
page.open(address, function (status) {
|
140
|
-
if (status
|
148
|
+
if (status != 'success') {
|
141
149
|
console.log('FAILED_LOADING_URL');
|
142
150
|
} else {
|
143
151
|
console.log('DONE_LOADING_URL');
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantom_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 9
|
10
|
+
version: 1.2.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Sudmann
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-10-05 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|