Class: SeleniumSpider::Controller
- Inherits:
-
Object
- Object
- SeleniumSpider::Controller
- Defined in:
- lib/selenium_spider/controller.rb
Class Method Summary collapse
Instance Method Summary collapse
- #extract_info(location: nil, driver: nil) ⇒ Object
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
- #run ⇒ Object
Constructor Details
#initialize ⇒ Controller
9 10 11 12 |
# File 'lib/selenium_spider/controller.rb', line 9 def initialize @type = self.class.to_s.sub('Controller', '') @pagination_class = @type + 'Pagination' end |
Class Method Details
.crawl_urls(urls) ⇒ Object
5 6 7 |
# File 'lib/selenium_spider/controller.rb', line 5 def self.crawl_urls(urls) @@urls = urls end |
Instance Method Details
#extract_info(location: nil, driver: nil) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/selenium_spider/controller.rb', line 36 def extract_info(location: nil, driver: nil) model = SeleniumSpider.const_get(@type).new(location: location, driver: driver) @pagination.attributes.each do |key, value| model.set_attributes_value(key, value.value) end puts model.output_as_json model.quit if location end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/selenium_spider/controller.rb', line 14 def run @@urls.each_with_index do |url, idx| @pagination = SeleniumSpider.const_get(@pagination_class).new(url) @pagination.before_crawl idx while true if (detail_links = @pagination.detail_links) detail_links.each do |detail_link| extract_info location: detail_link end else extract_info driver: @pagination.driver end break if !@pagination.continue? @pagination.next end @pagination.quit end end |