Class: GoogleAjaxCrawler::Drivers::Driver
- Inherits:
-
Object
- Object
- GoogleAjaxCrawler::Drivers::Driver
- Defined in:
- lib/google_ajax_crawler/drivers/driver.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #default_page_loaded_test ⇒ Object
- #evaluate_script(javascript) ⇒ Object
- #get_content(uri) ⇒ Object
- #html ⇒ Object
-
#initialize(options) ⇒ Driver
constructor
A new instance of Driver.
- #is_page_loaded? ⇒ Boolean
- #visit(url) ⇒ Object
- #wait_until_page_is_fully_loaded ⇒ Object
Constructor Details
#initialize(options) ⇒ Driver
Returns a new instance of Driver.
7 8 9 |
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 7 def initialize() @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 5 def @options end |
Instance Method Details
#default_page_loaded_test ⇒ Object
19 20 21 |
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 19 def default_page_loaded_test raise "Driver Not Specified" end |
#evaluate_script(javascript) ⇒ Object
15 16 17 |
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 15 def evaluate_script(javascript) raise "Driver Not Specified" end |
#get_content(uri) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 27 def get_content(uri) begin puts "::requesting: #{uri}" visit uri.to_s wait_until_page_is_fully_loaded rescue Timeout::Error puts "-- Page Rendering Timed out: --\n"\ "Either your page_loaded_test didn't successfully detect when your page had loaded, \n"\ "or your page took longer than #{.timeout} seconds to load \n"\ "-- Returning page snapshot in its present state --" end html end |
#html ⇒ Object
23 24 25 |
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 23 def html raise "Driver Not Specified" end |
#is_page_loaded? ⇒ Boolean
41 42 43 44 45 |
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 41 def is_page_loaded? return evaluate_script(.page_loaded_js) unless .page_loaded_js.nil? return .page_loaded_test.call(self) unless .page_loaded_test.nil? default_page_loaded_test end |
#visit(url) ⇒ Object
11 12 13 |
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 11 def visit(url) raise "Driver Not Specified" end |
#wait_until_page_is_fully_loaded ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 47 def wait_until_page_is_fully_loaded Timeout::timeout(.timeout) do begin sleep(.poll_interval) while !is_page_loaded? rescue #...squelch puts "Exception: #{$!}" end end end |