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.
7 8 9 10 |
# File 'lib/phantom_ruby_browser.rb', line 7 def initialize(location) @location = location @phantomjs = Phantomjs end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
5 6 7 |
# File 'lib/phantom_ruby_browser.rb', line 5 def location @location end |
#phantomjs ⇒ Object (readonly)
Returns the value of attribute phantomjs.
5 6 7 |
# File 'lib/phantom_ruby_browser.rb', line 5 def phantomjs @phantomjs end |
Instance Method Details
#content ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/phantom_ruby_browser.rb', line 12 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/phantom_ruby_browser.rb', line 23 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 |