phantomjs.rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +16 -0
- data/Rakefile +1 -0
- data/lib/phantomjs.rb +53 -0
- data/lib/phantomjs/version.rb +3 -0
- data/phantomjs.rb.gemspec +24 -0
- data/spec/phantomjs_spec.rb +13 -0
- data/spec/runner.js +2 -0
- data/vendor/phantomjs-1.4.1_OSX/ChangeLog +145 -0
- data/vendor/phantomjs-1.4.1_OSX/LICENSE.BSD +22 -0
- data/vendor/phantomjs-1.4.1_OSX/README.md +33 -0
- data/vendor/phantomjs-1.4.1_OSX/bin/Info.plist +12 -0
- data/vendor/phantomjs-1.4.1_OSX/bin/phantomjs +0 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/arguments.coffee +6 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/arguments.js +8 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.coffee +46 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.js +51 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/countdown.coffee +8 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/countdown.js +9 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.coffee +40 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.js +57 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/direction.coffee +29 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/direction.js +34 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.coffee +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.js +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/features.js +30 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/fibo.coffee +8 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/fibo.js +9 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/follow.coffee +54 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/follow.js +59 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/hello.coffee +2 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/hello.js +2 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.coffee +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.js +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/injectme.coffee +23 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/injectme.js +25 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.coffee +13 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.js +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/modernizr.js +1116 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/movies.coffee +13 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/movies.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netlog.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netlog.js +23 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.coffee +109 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.js +131 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.coffee +12 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.js +16 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.coffee +13 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.js +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/pizza.coffee +18 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/pizza.js +20 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/post.coffee +12 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/post.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.coffee +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.js +27 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.coffee +48 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.js +60 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.coffee +59 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.js +77 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.coffee +62 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.js +74 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/scandir.coffee +15 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/scandir.js +21 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.js +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.coffee +35 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.js +40 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.js +24 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/technews.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/technews.js +16 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/tweets.coffee +30 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/tweets.js +36 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.coffee +18 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.js +24 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/useragent.coffee +11 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/useragent.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/version.coffee +5 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/version.js +5 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.coffee +48 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.js +57 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/weather.coffee +48 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/weather.js +57 -0
- data/vendor/phantomjs-1.4.1_OSX/lib/jquery.js +8374 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/ChangeLog +177 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/LICENSE.BSD +22 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/README.md +33 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/Info.plist +12 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/phantomjs +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.coffee +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.js +9 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.coffee +46 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.js +51 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.coffee +8 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.js +9 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.coffee +41 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.js +58 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.coffee +30 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.js +35 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.coffee +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.js +24 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/features.js +30 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.coffee +8 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.js +9 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.coffee +29 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.js +34 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.coffee +2 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.js +2 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.coffee +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.js +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.coffee +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.js +25 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.coffee +13 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.js +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/modernizr.js +1116 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.coffee +13 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.js +25 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.coffee +110 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.js +132 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.coffee +12 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.js +16 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.coffee +13 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.js +19 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.js +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.coffee +12 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/postserver.js +34 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printenv.js +10 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printmargins.js +35 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.coffee +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.js +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.coffee +50 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.js +62 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.coffee +61 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.js +79 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.coffee +64 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.js +76 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.coffee +16 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.js +22 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.coffee +17 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.js +19 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/server.js +43 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/serverkeepalive.js +34 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.coffee +38 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.js +42 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.coffee +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.js +25 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.coffee +17 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.js +16 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.coffee +31 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.js +37 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.js +24 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.coffee +11 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.coffee +5 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.js +5 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.coffee +48 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.js +57 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.coffee +49 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.js +58 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.prl +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8.0 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.prl +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8.0 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.prl +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8.0 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.prl +6 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9.0 +0 -0
- metadata +252 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
# List movies from kids-in-mind.com
|
2
|
+
|
3
|
+
window.cbfunc = (data) ->
|
4
|
+
globaldata = data
|
5
|
+
list = data.query.results.movie
|
6
|
+
for item in list
|
7
|
+
console.log item.title + ' [' + item.rating.MPAA.content + ']'
|
8
|
+
phantom.exit()
|
9
|
+
|
10
|
+
el = document.createElement 'script'
|
11
|
+
el.src =
|
12
|
+
"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20movies.kids-in-mind&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=window.cbfunc"
|
13
|
+
document.body.appendChild el
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// List movies from kids-in-mind.com
|
2
|
+
|
3
|
+
var cbfunc = function (data) {
|
4
|
+
globaldata= data;
|
5
|
+
var list = data.query.results.movie;
|
6
|
+
list.forEach(function (item) {
|
7
|
+
console.log(item.title + ' [' + item.rating.MPAA.content + ']');
|
8
|
+
});
|
9
|
+
phantom.exit();
|
10
|
+
};
|
11
|
+
|
12
|
+
var el = document.createElement('script');
|
13
|
+
el.src = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20movies.kids-in-mind&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=cbfunc';
|
14
|
+
document.body.appendChild(el);
|
@@ -0,0 +1,18 @@
|
|
1
|
+
page = require('webpage').create()
|
2
|
+
system = require 'system'
|
3
|
+
|
4
|
+
if system.args.length is 1
|
5
|
+
console.log 'Usage: netlog.coffee <some URL>'
|
6
|
+
phantom.exit()
|
7
|
+
else
|
8
|
+
address = system.args[1]
|
9
|
+
page.onResourceRequested = (req) ->
|
10
|
+
console.log 'requested ' + JSON.stringify(req, undefined, 4)
|
11
|
+
|
12
|
+
page.onResourceReceived = (res) ->
|
13
|
+
console.log 'received ' + JSON.stringify(res, undefined, 4)
|
14
|
+
|
15
|
+
page.open address, (status) ->
|
16
|
+
if status isnt 'success'
|
17
|
+
console.log 'FAIL to load the address'
|
18
|
+
phantom.exit()
|
@@ -0,0 +1,25 @@
|
|
1
|
+
var page = require('webpage').create(),
|
2
|
+
system = require('system'),
|
3
|
+
address;
|
4
|
+
|
5
|
+
if (system.args.length === 1) {
|
6
|
+
console.log('Usage: netlog.js <some URL>');
|
7
|
+
phantom.exit();
|
8
|
+
} else {
|
9
|
+
address = system.args[1];
|
10
|
+
|
11
|
+
page.onResourceRequested = function (req) {
|
12
|
+
console.log('requested: ' + JSON.stringify(req, undefined, 4));
|
13
|
+
};
|
14
|
+
|
15
|
+
page.onResourceReceived = function (res) {
|
16
|
+
console.log('received: ' + JSON.stringify(res, undefined, 4));
|
17
|
+
};
|
18
|
+
|
19
|
+
page.open(address, function (status) {
|
20
|
+
if (status !== 'success') {
|
21
|
+
console.log('FAIL to load the address');
|
22
|
+
}
|
23
|
+
phantom.exit();
|
24
|
+
});
|
25
|
+
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
if not Date::toISOString
|
2
|
+
Date::toISOString = ->
|
3
|
+
pad = (n) ->
|
4
|
+
if n < 10 then '0' + n else n
|
5
|
+
ms = (n) ->
|
6
|
+
if n < 10 then '00' + n else (if n < 100 then '0' + n else n)
|
7
|
+
@getFullYear() + '-' +
|
8
|
+
pad(@getMonth() + 1) + '-' +
|
9
|
+
pad(@getDate()) + 'T' +
|
10
|
+
pad(@getHours()) + ':' +
|
11
|
+
pad(@getMinutes()) + ':' +
|
12
|
+
pad(@getSeconds()) + '.' +
|
13
|
+
ms(@getMilliseconds()) + 'Z'
|
14
|
+
|
15
|
+
createHAR = (address, title, startTime, resources) ->
|
16
|
+
entries = []
|
17
|
+
|
18
|
+
resources.forEach (resource) ->
|
19
|
+
request = resource.request
|
20
|
+
startReply = resource.startReply
|
21
|
+
endReply = resource.endReply
|
22
|
+
|
23
|
+
if not request or not startReply or not endReply
|
24
|
+
return
|
25
|
+
|
26
|
+
entries.push
|
27
|
+
startedDateTime: request.time.toISOString()
|
28
|
+
time: endReply.time - request.time
|
29
|
+
request:
|
30
|
+
method: request.method
|
31
|
+
url: request.url
|
32
|
+
httpVersion: 'HTTP/1.1'
|
33
|
+
cookies: []
|
34
|
+
headers: request.headers
|
35
|
+
queryString: []
|
36
|
+
headersSize: -1
|
37
|
+
bodySize: -1
|
38
|
+
|
39
|
+
response:
|
40
|
+
status: endReply.status
|
41
|
+
statusText: endReply.statusText
|
42
|
+
httpVersion: 'HTTP/1.1'
|
43
|
+
cookies: []
|
44
|
+
headers: endReply.headers
|
45
|
+
redirectURL: ''
|
46
|
+
headersSize: -1
|
47
|
+
bodySize: startReply.bodySize
|
48
|
+
content:
|
49
|
+
size: startReply.bodySize
|
50
|
+
mimeType: endReply.contentType
|
51
|
+
|
52
|
+
cache: {}
|
53
|
+
timings:
|
54
|
+
blocked: 0
|
55
|
+
dns: -1
|
56
|
+
connect: -1
|
57
|
+
send: 0
|
58
|
+
wait: startReply.time - request.time
|
59
|
+
receive: endReply.time - startReply.time
|
60
|
+
ssl: -1
|
61
|
+
|
62
|
+
log:
|
63
|
+
version: '1.2'
|
64
|
+
creator:
|
65
|
+
name: 'PhantomJS'
|
66
|
+
version: phantom.version.major + '.' + phantom.version.minor + '.' + phantom.version.patch
|
67
|
+
|
68
|
+
pages: [
|
69
|
+
startedDateTime: startTime.toISOString()
|
70
|
+
id: address
|
71
|
+
title: title
|
72
|
+
pageTimings: {}
|
73
|
+
]
|
74
|
+
entries: entries
|
75
|
+
|
76
|
+
page = require('webpage').create()
|
77
|
+
system = require 'system'
|
78
|
+
|
79
|
+
if system.args.length is 1
|
80
|
+
console.log 'Usage: netsniff.coffee <some URL>'
|
81
|
+
phantom.exit()
|
82
|
+
else
|
83
|
+
page.address = system.args[1]
|
84
|
+
page.resources = []
|
85
|
+
|
86
|
+
page.onLoadStarted = ->
|
87
|
+
page.startTime = new Date()
|
88
|
+
|
89
|
+
page.onResourceRequested = (req) ->
|
90
|
+
page.resources[req.id] =
|
91
|
+
request: req
|
92
|
+
startReply: null
|
93
|
+
endReply: null
|
94
|
+
|
95
|
+
page.onResourceReceived = (res) ->
|
96
|
+
if res.stage is 'start'
|
97
|
+
page.resources[res.id].startReply = res
|
98
|
+
if res.stage is 'end'
|
99
|
+
page.resources[res.id].endReply = res
|
100
|
+
|
101
|
+
page.open page.address, (status) ->
|
102
|
+
if status isnt 'success'
|
103
|
+
console.log 'FAIL to load the address'
|
104
|
+
else
|
105
|
+
page.title = page.evaluate ->
|
106
|
+
document.title
|
107
|
+
|
108
|
+
har = createHAR page.address, page.title, page.startTime, page.resources
|
109
|
+
console.log JSON.stringify har, undefined, 4
|
110
|
+
phantom.exit()
|
@@ -0,0 +1,132 @@
|
|
1
|
+
if (!Date.prototype.toISOString) {
|
2
|
+
Date.prototype.toISOString = function () {
|
3
|
+
function pad(n) { return n < 10 ? '0' + n : n; }
|
4
|
+
function ms(n) { return n < 10 ? '00'+ n : n < 100 ? '0' + n : n }
|
5
|
+
return this.getFullYear() + '-' +
|
6
|
+
pad(this.getMonth() + 1) + '-' +
|
7
|
+
pad(this.getDate()) + 'T' +
|
8
|
+
pad(this.getHours()) + ':' +
|
9
|
+
pad(this.getMinutes()) + ':' +
|
10
|
+
pad(this.getSeconds()) + '.' +
|
11
|
+
ms(this.getMilliseconds()) + 'Z';
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
function createHAR(address, title, startTime, resources)
|
16
|
+
{
|
17
|
+
var entries = [];
|
18
|
+
|
19
|
+
resources.forEach(function (resource) {
|
20
|
+
var request = resource.request,
|
21
|
+
startReply = resource.startReply,
|
22
|
+
endReply = resource.endReply;
|
23
|
+
|
24
|
+
if (!request || !startReply || !endReply) {
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
|
28
|
+
entries.push({
|
29
|
+
startedDateTime: request.time.toISOString(),
|
30
|
+
time: endReply.time - request.time,
|
31
|
+
request: {
|
32
|
+
method: request.method,
|
33
|
+
url: request.url,
|
34
|
+
httpVersion: "HTTP/1.1",
|
35
|
+
cookies: [],
|
36
|
+
headers: request.headers,
|
37
|
+
queryString: [],
|
38
|
+
headersSize: -1,
|
39
|
+
bodySize: -1
|
40
|
+
},
|
41
|
+
response: {
|
42
|
+
status: endReply.status,
|
43
|
+
statusText: endReply.statusText,
|
44
|
+
httpVersion: "HTTP/1.1",
|
45
|
+
cookies: [],
|
46
|
+
headers: endReply.headers,
|
47
|
+
redirectURL: "",
|
48
|
+
headersSize: -1,
|
49
|
+
bodySize: startReply.bodySize,
|
50
|
+
content: {
|
51
|
+
size: startReply.bodySize,
|
52
|
+
mimeType: endReply.contentType
|
53
|
+
}
|
54
|
+
},
|
55
|
+
cache: {},
|
56
|
+
timings: {
|
57
|
+
blocked: 0,
|
58
|
+
dns: -1,
|
59
|
+
connect: -1,
|
60
|
+
send: 0,
|
61
|
+
wait: startReply.time - request.time,
|
62
|
+
receive: endReply.time - startReply.time,
|
63
|
+
ssl: -1
|
64
|
+
}
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
68
|
+
return {
|
69
|
+
log: {
|
70
|
+
version: '1.2',
|
71
|
+
creator: {
|
72
|
+
name: "PhantomJS",
|
73
|
+
version: phantom.version.major + '.' + phantom.version.minor +
|
74
|
+
'.' + phantom.version.patch
|
75
|
+
},
|
76
|
+
pages: [{
|
77
|
+
startedDateTime: startTime.toISOString(),
|
78
|
+
id: address,
|
79
|
+
title: title,
|
80
|
+
pageTimings: {}
|
81
|
+
}],
|
82
|
+
entries: entries
|
83
|
+
}
|
84
|
+
};
|
85
|
+
}
|
86
|
+
|
87
|
+
var page = require('webpage').create(),
|
88
|
+
system = require('system');
|
89
|
+
|
90
|
+
if (system.args.length === 1) {
|
91
|
+
console.log('Usage: netsniff.coffee <some URL>');
|
92
|
+
phantom.exit();
|
93
|
+
} else {
|
94
|
+
|
95
|
+
page.address = system.args[1];
|
96
|
+
page.resources = [];
|
97
|
+
|
98
|
+
page.onLoadStarted = function () {
|
99
|
+
page.startTime = new Date();
|
100
|
+
};
|
101
|
+
|
102
|
+
page.onResourceRequested = function (req) {
|
103
|
+
page.resources[req.id] = {
|
104
|
+
request: req,
|
105
|
+
startReply: null,
|
106
|
+
endReply: null
|
107
|
+
};
|
108
|
+
};
|
109
|
+
|
110
|
+
page.onResourceReceived = function (res) {
|
111
|
+
if (res.stage === 'start') {
|
112
|
+
page.resources[res.id].startReply = res;
|
113
|
+
}
|
114
|
+
if (res.stage === 'end') {
|
115
|
+
page.resources[res.id].endReply = res;
|
116
|
+
}
|
117
|
+
};
|
118
|
+
|
119
|
+
page.open(page.address, function (status) {
|
120
|
+
var har;
|
121
|
+
if (status !== 'success') {
|
122
|
+
console.log('FAIL to load the address');
|
123
|
+
} else {
|
124
|
+
page.title = page.evaluate(function () {
|
125
|
+
return document.title;
|
126
|
+
});
|
127
|
+
har = createHAR(page.address, page.title, page.startTime, page.resources);
|
128
|
+
console.log(JSON.stringify(har, undefined, 4));
|
129
|
+
}
|
130
|
+
phantom.exit();
|
131
|
+
});
|
132
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
helloWorld = () -> console.log phantom.outputEncoding + ": こんにちは、世界!"
|
2
|
+
|
3
|
+
console.log "Using default encoding..."
|
4
|
+
helloWorld()
|
5
|
+
|
6
|
+
console.log "\nUsing other encodings..."
|
7
|
+
for enc in ["euc-jp", "sjis", "utf8", "System"]
|
8
|
+
do (enc) ->
|
9
|
+
phantom.outputEncoding = enc
|
10
|
+
helloWorld()
|
11
|
+
|
12
|
+
phantom.exit()
|
@@ -0,0 +1,16 @@
|
|
1
|
+
function helloWorld() {
|
2
|
+
console.log(phantom.outputEncoding + ": こんにちは、世界!");
|
3
|
+
}
|
4
|
+
|
5
|
+
console.log("Using default encoding...");
|
6
|
+
helloWorld();
|
7
|
+
|
8
|
+
console.log("\nUsing other encodings...");
|
9
|
+
|
10
|
+
var encodings = ["euc-jp", "sjis", "utf8", "System"];
|
11
|
+
for (var i = 0; i < encodings.length; i++) {
|
12
|
+
phantom.outputEncoding = encodings[i];
|
13
|
+
helloWorld();
|
14
|
+
}
|
15
|
+
|
16
|
+
phantom.exit()
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
|
2
|
+
|
3
|
+
page = require('webpage').create()
|
4
|
+
|
5
|
+
page.onConsoleMessage = (msg) -> console.log msg
|
6
|
+
|
7
|
+
page.open "http://www.phantomjs.org", (status) ->
|
8
|
+
if status is "success"
|
9
|
+
page.includeJs "http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", ->
|
10
|
+
page.evaluate ->
|
11
|
+
console.log "$(\"#intro\").text() -> " + $("#intro").text()
|
12
|
+
phantom.exit()
|
13
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
|
2
|
+
|
3
|
+
var page = require('webpage').create();
|
4
|
+
|
5
|
+
page.onConsoleMessage = function(msg) {
|
6
|
+
console.log(msg);
|
7
|
+
};
|
8
|
+
|
9
|
+
page.open("http://www.phantomjs.org", function(status) {
|
10
|
+
if ( status === "success" ) {
|
11
|
+
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
|
12
|
+
page.evaluate(function() {
|
13
|
+
console.log("$(\"#intro\").text() -> " + $("#intro").text());
|
14
|
+
});
|
15
|
+
phantom.exit();
|
16
|
+
});
|
17
|
+
}
|
18
|
+
});
|
19
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Find pizza in Mountain View using Yelp
|
2
|
+
|
3
|
+
page = require('webpage').create()
|
4
|
+
url = 'http://lite.yelp.com/search?find_desc=pizza&find_loc=94040&find_submit=Search'
|
5
|
+
|
6
|
+
page.open url,
|
7
|
+
(status) ->
|
8
|
+
if status isnt 'success'
|
9
|
+
console.log 'Unable to access network'
|
10
|
+
else
|
11
|
+
results = page.evaluate ->
|
12
|
+
pizza = []
|
13
|
+
list = document.querySelectorAll 'span.address'
|
14
|
+
for item in list
|
15
|
+
pizza.push(item.innerText)
|
16
|
+
return pizza
|
17
|
+
console.log results.join('\n')
|
18
|
+
phantom.exit()
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// Find pizza in Mountain View using Yelp
|
2
|
+
|
3
|
+
var page = require('webpage').create(),
|
4
|
+
url = 'http://lite.yelp.com/search?find_desc=pizza&find_loc=94040&find_submit=Search';
|
5
|
+
|
6
|
+
page.open(url, function (status) {
|
7
|
+
if (status !== 'success') {
|
8
|
+
console.log('Unable to access network');
|
9
|
+
} else {
|
10
|
+
var results = page.evaluate(function() {
|
11
|
+
var list = document.querySelectorAll('span.address'), pizza = [], i;
|
12
|
+
for (i = 0; i < list.length; i++) {
|
13
|
+
pizza.push(list[i].innerText);
|
14
|
+
}
|
15
|
+
return pizza;
|
16
|
+
});
|
17
|
+
console.log(results.join('\n'));
|
18
|
+
}
|
19
|
+
phantom.exit();
|
20
|
+
});
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Example using HTTP POST operation
|
2
|
+
|
3
|
+
page = require('webpage').create()
|
4
|
+
server = 'http://posttestserver.com/post.php?dump'
|
5
|
+
data = 'universe=expanding&answer=42'
|
6
|
+
|
7
|
+
page.open server, 'post', data, (status) ->
|
8
|
+
if status isnt 'success'
|
9
|
+
console.log 'Unable to post!'
|
10
|
+
else
|
11
|
+
console.log page.content
|
12
|
+
phantom.exit()
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// Example using HTTP POST operation
|
2
|
+
|
3
|
+
var page = require('webpage').create(),
|
4
|
+
server = 'http://posttestserver.com/post.php?dump',
|
5
|
+
data = 'universe=expanding&answer=42';
|
6
|
+
|
7
|
+
page.open(server, 'post', data, function (status) {
|
8
|
+
if (status !== 'success') {
|
9
|
+
console.log('Unable to post!');
|
10
|
+
} else {
|
11
|
+
console.log(page.content);
|
12
|
+
}
|
13
|
+
phantom.exit();
|
14
|
+
});
|