phantomjs.rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. data/.autotest +7 -0
  2. data/.gitignore +4 -0
  3. data/Gemfile +4 -0
  4. data/README.md +16 -0
  5. data/Rakefile +1 -0
  6. data/lib/phantomjs.rb +53 -0
  7. data/lib/phantomjs/version.rb +3 -0
  8. data/phantomjs.rb.gemspec +24 -0
  9. data/spec/phantomjs_spec.rb +13 -0
  10. data/spec/runner.js +2 -0
  11. data/vendor/phantomjs-1.4.1_OSX/ChangeLog +145 -0
  12. data/vendor/phantomjs-1.4.1_OSX/LICENSE.BSD +22 -0
  13. data/vendor/phantomjs-1.4.1_OSX/README.md +33 -0
  14. data/vendor/phantomjs-1.4.1_OSX/bin/Info.plist +12 -0
  15. data/vendor/phantomjs-1.4.1_OSX/bin/phantomjs +0 -0
  16. data/vendor/phantomjs-1.4.1_OSX/examples/arguments.coffee +6 -0
  17. data/vendor/phantomjs-1.4.1_OSX/examples/arguments.js +8 -0
  18. data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.coffee +46 -0
  19. data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.js +51 -0
  20. data/vendor/phantomjs-1.4.1_OSX/examples/countdown.coffee +8 -0
  21. data/vendor/phantomjs-1.4.1_OSX/examples/countdown.js +9 -0
  22. data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.coffee +40 -0
  23. data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.js +57 -0
  24. data/vendor/phantomjs-1.4.1_OSX/examples/direction.coffee +29 -0
  25. data/vendor/phantomjs-1.4.1_OSX/examples/direction.js +34 -0
  26. data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.coffee +19 -0
  27. data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.js +22 -0
  28. data/vendor/phantomjs-1.4.1_OSX/examples/features.js +30 -0
  29. data/vendor/phantomjs-1.4.1_OSX/examples/fibo.coffee +8 -0
  30. data/vendor/phantomjs-1.4.1_OSX/examples/fibo.js +9 -0
  31. data/vendor/phantomjs-1.4.1_OSX/examples/follow.coffee +54 -0
  32. data/vendor/phantomjs-1.4.1_OSX/examples/follow.js +59 -0
  33. data/vendor/phantomjs-1.4.1_OSX/examples/hello.coffee +2 -0
  34. data/vendor/phantomjs-1.4.1_OSX/examples/hello.js +2 -0
  35. data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.coffee +19 -0
  36. data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.js +22 -0
  37. data/vendor/phantomjs-1.4.1_OSX/examples/injectme.coffee +23 -0
  38. data/vendor/phantomjs-1.4.1_OSX/examples/injectme.js +25 -0
  39. data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.coffee +13 -0
  40. data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.js +14 -0
  41. data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.coffee +17 -0
  42. data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.js +22 -0
  43. data/vendor/phantomjs-1.4.1_OSX/examples/modernizr.js +1116 -0
  44. data/vendor/phantomjs-1.4.1_OSX/examples/movies.coffee +13 -0
  45. data/vendor/phantomjs-1.4.1_OSX/examples/movies.js +14 -0
  46. data/vendor/phantomjs-1.4.1_OSX/examples/netlog.coffee +17 -0
  47. data/vendor/phantomjs-1.4.1_OSX/examples/netlog.js +23 -0
  48. data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.coffee +109 -0
  49. data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.js +131 -0
  50. data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.coffee +12 -0
  51. data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.js +16 -0
  52. data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.coffee +13 -0
  53. data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.js +19 -0
  54. data/vendor/phantomjs-1.4.1_OSX/examples/pizza.coffee +18 -0
  55. data/vendor/phantomjs-1.4.1_OSX/examples/pizza.js +20 -0
  56. data/vendor/phantomjs-1.4.1_OSX/examples/post.coffee +12 -0
  57. data/vendor/phantomjs-1.4.1_OSX/examples/post.js +14 -0
  58. data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.coffee +22 -0
  59. data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.js +27 -0
  60. data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.coffee +48 -0
  61. data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.js +60 -0
  62. data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.coffee +59 -0
  63. data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.js +77 -0
  64. data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.coffee +62 -0
  65. data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.js +74 -0
  66. data/vendor/phantomjs-1.4.1_OSX/examples/scandir.coffee +15 -0
  67. data/vendor/phantomjs-1.4.1_OSX/examples/scandir.js +21 -0
  68. data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.coffee +17 -0
  69. data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.js +19 -0
  70. data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.coffee +35 -0
  71. data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.js +40 -0
  72. data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.coffee +17 -0
  73. data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.js +24 -0
  74. data/vendor/phantomjs-1.4.1_OSX/examples/technews.coffee +17 -0
  75. data/vendor/phantomjs-1.4.1_OSX/examples/technews.js +16 -0
  76. data/vendor/phantomjs-1.4.1_OSX/examples/tweets.coffee +30 -0
  77. data/vendor/phantomjs-1.4.1_OSX/examples/tweets.js +36 -0
  78. data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.coffee +18 -0
  79. data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.js +24 -0
  80. data/vendor/phantomjs-1.4.1_OSX/examples/useragent.coffee +11 -0
  81. data/vendor/phantomjs-1.4.1_OSX/examples/useragent.js +14 -0
  82. data/vendor/phantomjs-1.4.1_OSX/examples/version.coffee +5 -0
  83. data/vendor/phantomjs-1.4.1_OSX/examples/version.js +5 -0
  84. data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.coffee +48 -0
  85. data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.js +57 -0
  86. data/vendor/phantomjs-1.4.1_OSX/examples/weather.coffee +48 -0
  87. data/vendor/phantomjs-1.4.1_OSX/examples/weather.js +57 -0
  88. data/vendor/phantomjs-1.4.1_OSX/lib/jquery.js +8374 -0
  89. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/ChangeLog +177 -0
  90. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/LICENSE.BSD +22 -0
  91. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/README.md +33 -0
  92. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/Info.plist +12 -0
  93. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/phantomjs +0 -0
  94. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.coffee +7 -0
  95. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.js +9 -0
  96. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.coffee +46 -0
  97. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.js +51 -0
  98. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.coffee +8 -0
  99. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.js +9 -0
  100. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.coffee +41 -0
  101. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.js +58 -0
  102. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.coffee +30 -0
  103. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.js +35 -0
  104. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.coffee +20 -0
  105. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.js +24 -0
  106. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/features.js +30 -0
  107. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.coffee +8 -0
  108. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.js +9 -0
  109. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.coffee +29 -0
  110. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.js +34 -0
  111. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.coffee +2 -0
  112. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.js +2 -0
  113. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.coffee +20 -0
  114. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.js +23 -0
  115. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.coffee +23 -0
  116. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.js +25 -0
  117. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.coffee +13 -0
  118. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.js +14 -0
  119. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.coffee +18 -0
  120. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.js +23 -0
  121. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/modernizr.js +1116 -0
  122. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.coffee +13 -0
  123. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.js +14 -0
  124. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.coffee +18 -0
  125. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.js +25 -0
  126. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.coffee +110 -0
  127. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.js +132 -0
  128. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.coffee +12 -0
  129. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.js +16 -0
  130. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.coffee +13 -0
  131. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.js +19 -0
  132. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.coffee +18 -0
  133. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.js +20 -0
  134. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.coffee +12 -0
  135. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.js +14 -0
  136. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/postserver.js +34 -0
  137. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printenv.js +10 -0
  138. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printmargins.js +35 -0
  139. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.coffee +23 -0
  140. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.js +28 -0
  141. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.coffee +50 -0
  142. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.js +62 -0
  143. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.coffee +61 -0
  144. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.js +79 -0
  145. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.coffee +64 -0
  146. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.js +76 -0
  147. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.coffee +16 -0
  148. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.js +22 -0
  149. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.coffee +17 -0
  150. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.js +19 -0
  151. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/server.js +43 -0
  152. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/serverkeepalive.js +34 -0
  153. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.coffee +38 -0
  154. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.js +42 -0
  155. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.coffee +20 -0
  156. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.js +25 -0
  157. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.coffee +17 -0
  158. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.js +16 -0
  159. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.coffee +31 -0
  160. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.js +37 -0
  161. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.coffee +18 -0
  162. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.js +24 -0
  163. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.coffee +11 -0
  164. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.js +14 -0
  165. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.coffee +5 -0
  166. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.js +5 -0
  167. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.coffee +48 -0
  168. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.js +57 -0
  169. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.coffee +49 -0
  170. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.js +58 -0
  171. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.la +28 -0
  172. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.prl +7 -0
  173. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so +0 -0
  174. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4 +0 -0
  175. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8 +0 -0
  176. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8.0 +0 -0
  177. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.la +28 -0
  178. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.prl +7 -0
  179. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so +0 -0
  180. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4 +0 -0
  181. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8 +0 -0
  182. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8.0 +0 -0
  183. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.la +28 -0
  184. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.prl +7 -0
  185. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so +0 -0
  186. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4 +0 -0
  187. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8 +0 -0
  188. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8.0 +0 -0
  189. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.la +28 -0
  190. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.prl +6 -0
  191. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so +0 -0
  192. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4 +0 -0
  193. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9 +0 -0
  194. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9.0 +0 -0
  195. 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,17 @@
1
+ page = require('webpage').create()
2
+ address = phantom.args[0]
3
+
4
+ if phantom.args.length is 0
5
+ console.log 'Usage: netlog.coffee <some URL>'
6
+ phantom.exit()
7
+ else
8
+ page.onResourceRequested = (req) ->
9
+ console.log 'requested ' + JSON.stringify(req, undefined, 4)
10
+
11
+ page.onResourceReceived = (res) ->
12
+ console.log 'received ' + JSON.stringify(res, undefined, 4)
13
+
14
+ page.open address, (status) ->
15
+ if status isnt 'success'
16
+ console.log 'FAIL to load the address'
17
+ phantom.exit()
@@ -0,0 +1,23 @@
1
+ var page = require('webpage').create(),
2
+ address = phantom.args[0];
3
+
4
+ if (phantom.args.length === 0) {
5
+ console.log('Usage: netlog.js <some URL>');
6
+ phantom.exit();
7
+ } else {
8
+
9
+ page.onResourceRequested = function (req) {
10
+ console.log('requested: ' + JSON.stringify(req, undefined, 4));
11
+ };
12
+
13
+ page.onResourceReceived = function (res) {
14
+ console.log('received: ' + JSON.stringify(res, undefined, 4));
15
+ };
16
+
17
+ page.open(address, function (status) {
18
+ if (status !== 'success') {
19
+ console.log('FAIL to load the address');
20
+ }
21
+ phantom.exit();
22
+ });
23
+ }
@@ -0,0 +1,109 @@
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
+
78
+ if phantom.args.length is 0
79
+ console.log 'Usage: netsniff.js <some URL>'
80
+ phantom.exit()
81
+ else
82
+ page.address = phantom.args[0]
83
+ page.resources = []
84
+
85
+ page.onLoadStarted = ->
86
+ page.startTime = new Date()
87
+
88
+ page.onResourceRequested = (req) ->
89
+ page.resources[req.id] =
90
+ request: req
91
+ startReply: null
92
+ endReply: null
93
+
94
+ page.onResourceReceived = (res) ->
95
+ if res.stage is 'start'
96
+ page.resources[res.id].startReply = res
97
+ if res.stage is 'end'
98
+ page.resources[res.id].endReply = res
99
+
100
+ page.open page.address, (status) ->
101
+ if status isnt 'success'
102
+ console.log 'FAIL to load the address'
103
+ else
104
+ page.title = page.evaluate ->
105
+ document.title
106
+
107
+ har = createHAR page.address, page.title, page.startTime, page.resources
108
+ console.log JSON.stringify har, undefined, 4
109
+ phantom.exit()
@@ -0,0 +1,131 @@
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
+
89
+ if (phantom.args.length === 0) {
90
+ console.log('Usage: netsniff.js <some URL>');
91
+ phantom.exit();
92
+ } else {
93
+
94
+ page.address = phantom.args[0];
95
+ page.resources = [];
96
+
97
+ page.onLoadStarted = function () {
98
+ page.startTime = new Date();
99
+ };
100
+
101
+ page.onResourceRequested = function (req) {
102
+ page.resources[req.id] = {
103
+ request: req,
104
+ startReply: null,
105
+ endReply: null
106
+ };
107
+ };
108
+
109
+ page.onResourceReceived = function (res) {
110
+ if (res.stage === 'start') {
111
+ page.resources[res.id].startReply = res;
112
+ }
113
+ if (res.stage === 'end') {
114
+ page.resources[res.id].endReply = res;
115
+ }
116
+ };
117
+
118
+ page.open(page.address, function (status) {
119
+ var har;
120
+ if (status !== 'success') {
121
+ console.log('FAIL to load the address');
122
+ } else {
123
+ page.title = page.evaluate(function () {
124
+ return document.title;
125
+ });
126
+ har = createHAR(page.address, page.title, page.startTime, page.resources);
127
+ console.log(JSON.stringify(har, undefined, 4));
128
+ }
129
+ phantom.exit();
130
+ });
131
+ }
@@ -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
+ });