Class: PhantomRubyBrowser
- Inherits:
-
Object
- Object
- PhantomRubyBrowser
- Defined in:
- lib/phantom_ruby_browser.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#phantomjs ⇒ Object
readonly
Returns the value of attribute phantomjs.
Instance Method Summary collapse
- #content ⇒ Object
- #content_after_click(link_selector = 'a') ⇒ Object
-
#initialize(location) ⇒ PhantomRubyBrowser
constructor
A new instance of PhantomRubyBrowser.
Constructor Details
#initialize(location) ⇒ PhantomRubyBrowser
Returns a new instance of PhantomRubyBrowser.
8 9 10 11 |
# File 'lib/phantom_ruby_browser.rb', line 8 def initialize(location) @location = location @phantomjs = Phantomjs end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
6 7 8 |
# File 'lib/phantom_ruby_browser.rb', line 6 def location @location end |
#phantomjs ⇒ Object (readonly)
Returns the value of attribute phantomjs.
6 7 8 |
# File 'lib/phantom_ruby_browser.rb', line 6 def phantomjs @phantomjs end |
Instance Method Details
#content ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/phantom_ruby_browser.rb', line 13 def content execute "var page = require('webpage').create(); page.open('#{@location}', function() { setTimeout(function(){var js = page.evaluate(function () { return document; }); console.log(js.all[0].outerHTML); phantom.exit();}, 1000); });" end |
#content_after_click(link_selector = 'a') ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/phantom_ruby_browser.rb', line 24 def content_after_click(link_selector = 'a') execute "var page = require('webpage').create(); page.open('#{@location}', function() { var coords = page.evaluate(function(){ return document.querySelector('#{link_selector}').getBoundingClientRect(); }); page.sendEvent('click', coords.left, coords.top); var js = page.evaluate(function () { return document; }); console.log(js.all[0].outerHTML); phantom.exit(); });" end |