Class: SeleniumSpider::Pagination
- Inherits:
-
SeleniumStandaloneDSL::Base
- Object
- SeleniumStandaloneDSL::Base
- SeleniumSpider::Pagination
- Defined in:
- lib/selenium_spider/pagination.rb
Constant Summary collapse
- @@attributes =
{}
Class Method Summary collapse
- .detail_links(selector) ⇒ Object
- .next_link(selector, find_by: :link_text) ⇒ Object
- .no_detail_link ⇒ Object
- .no_next_link ⇒ Object
Instance Method Summary collapse
- #attributes ⇒ Object
-
#before_crawl(times) ⇒ Object
You can define something to do before crawling.
- #continue? ⇒ Boolean
- #detail_links ⇒ Object
- #full_url(path) ⇒ Object
-
#initialize(start_url) ⇒ Pagination
constructor
A new instance of Pagination.
- #next ⇒ Object
- #register(attr_name_sym) {|| ... } ⇒ Object
Constructor Details
#initialize(start_url) ⇒ Pagination
Returns a new instance of Pagination.
28 29 30 31 32 |
# File 'lib/selenium_spider/pagination.rb', line 28 def initialize(start_url) super() visit start_url @uri = URI.parse(start_url) end |
Class Method Details
.detail_links(selector) ⇒ Object
20 21 22 |
# File 'lib/selenium_spider/pagination.rb', line 20 def self.detail_links(selector) @@detail_links_selector = selector end |
.next_link(selector, find_by: :link_text) ⇒ Object
11 12 13 14 |
# File 'lib/selenium_spider/pagination.rb', line 11 def self.next_link(selector, find_by: :link_text) @@next_link = selector @@next_link_find_by = find_by end |
.no_detail_link ⇒ Object
24 25 26 |
# File 'lib/selenium_spider/pagination.rb', line 24 def self.no_detail_link @@detail_links_selector = nil end |
.no_next_link ⇒ Object
16 17 18 |
# File 'lib/selenium_spider/pagination.rb', line 16 def self.no_next_link @@next_link = nil end |
Instance Method Details
#attributes ⇒ Object
7 8 9 |
# File 'lib/selenium_spider/pagination.rb', line 7 def attributes @@attributes end |
#before_crawl(times) ⇒ Object
You can define something to do before crawling
35 36 |
# File 'lib/selenium_spider/pagination.rb', line 35 def before_crawl(times) end |
#continue? ⇒ Boolean
52 53 54 55 |
# File 'lib/selenium_spider/pagination.rb', line 52 def continue? return false if !@@next_link has_element?(@@next_link, find_by: @@next_link_find_by) end |
#detail_links ⇒ Object
42 43 44 45 |
# File 'lib/selenium_spider/pagination.rb', line 42 def detail_links return false if !@@detail_links_selector search(@@detail_links_selector).map(&->(x) { full_url(x.attribute('href').value) } ) end |
#full_url(path) ⇒ Object
47 48 49 50 |
# File 'lib/selenium_spider/pagination.rb', line 47 def full_url(path) port = (@uri.port == 80) ? '' : ':' + @uri.port.to_s @uri.scheme + '://' + @uri.host + port + path end |
#next ⇒ Object
38 39 40 |
# File 'lib/selenium_spider/pagination.rb', line 38 def next click @@next_link, find_by: @@next_link_find_by end |
#register(attr_name_sym) {|| ... } ⇒ Object
57 58 59 60 |
# File 'lib/selenium_spider/pagination.rb', line 57 def register(attr_name_sym) @@attributes[attr_name_sym] = SeleniumSpider::Attribute.new yield @@attributes[attr_name_sym] if block_given? end |