Class: Arachnid2::Watir
- Inherits:
-
Object
- Object
- Arachnid2::Watir
- Includes:
- Exoskeleton
- Defined in:
- lib/arachnid2/watir.rb
Constant Summary collapse
- DEFAULT_AGENT =
:desktop
- DEFAULT_ORIENTATION =
:landscape
Instance Method Summary collapse
- #crawl(opts) ⇒ Object
-
#initialize(url) ⇒ Watir
constructor
A new instance of Watir.
Methods included from Exoskeleton
#bound_time, #bound_urls, #browser_type, #crawl_options, #extension_ignored?, #extract_hrefs, #in_docker?, #internal_link?, #make_absolute, #maximum_load_rate, #memory_danger?, #non_html_extensions, #preflight, #process, #proxy, #skip_link?, #timeout, #vacuum
Constructor Details
#initialize(url) ⇒ Watir
Returns a new instance of Watir.
8 9 10 11 |
# File 'lib/arachnid2/watir.rb', line 8 def initialize(url) @url = url @domain = Adomain[@url] end |
Instance Method Details
#crawl(opts) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/arachnid2/watir.rb', line 13 def crawl(opts) preflight(opts) watir_preflight until @global_queue.empty? @already_retried = false q = @global_queue.shift break if @global_visited.size >= [:max_urls] break if Time.now > [:time_limit] break if memory_danger? @global_visited.insert(q) begin begin browser.goto q rescue Selenium::WebDriver::Error::UnknownError => e # Firefox and Selenium, in their infinite wisdom # raise an error when a page cannot be loaded. # At the time of writing this, the page at # thewirecutter.com/cars/accessories-auto # causes such an issue (too many redirects). # This error handling moves us on from those pages. raise e unless e. =~ /.*Reached error page.*/i next end links = process(browser.url, browser.body.html) next unless links yield browser vacuum(links, browser.url) rescue => e raise e if @already_retried raise e unless "#{e.class}".include?("Selenium") || "#{e.class}".include?("Watir") @browser.close if @browser rescue nil @headless.destroy if @headless rescue nil @browser = nil @already_retried = true retry end end # until @global_queue.empty? ensure @browser.close if @browser rescue nil @headless.destroy if @headless rescue nil end |