Class: Mbanker::Crawler
- Inherits:
-
Object
- Object
- Mbanker::Crawler
- Defined in:
- lib/mbanker/crawler.rb
Constant Summary collapse
- BASE_URI =
'https://www.mbank.com.pl/'
- PATHS =
{ :login => 'logon.aspx', :logout => 'logout.aspx', :accounts_list => 'accounts_list.aspx', :account_details => 'account_details.aspx', :account_name_change => 'contract_change_name.aspx', :operation_history => 'account_oper_list.aspx' }
Instance Method Summary collapse
- #can_find?(selector) ⇒ Boolean
- #click(link_or_button) ⇒ Object
- #extract_action(link) ⇒ Object
- #extract_post_parameters(link) ⇒ Object
- #extract_text(selector) ⇒ Object
- #extract_texts(selector) ⇒ Object
- #find_first(selector) ⇒ Object
- #get_form ⇒ Object
-
#initialize ⇒ Crawler
constructor
A new instance of Crawler.
- #search(selector) ⇒ Object
- #submit_navigation_form(action, parameters) ⇒ Object
- #visit(path_name) ⇒ Object
Constructor Details
#initialize ⇒ Crawler
Returns a new instance of Crawler.
15 16 17 |
# File 'lib/mbanker/crawler.rb', line 15 def initialize @agent = Mechanize.new end |
Instance Method Details
#can_find?(selector) ⇒ Boolean
67 68 69 |
# File 'lib/mbanker/crawler.rb', line 67 def can_find? selector not search(selector).empty? end |
#click(link_or_button) ⇒ Object
23 24 25 26 27 |
# File 'lib/mbanker/crawler.rb', line 23 def click action = extract_action parameters = extract_post_parameters action, parameters end |
#extract_action(link) ⇒ Object
29 30 31 32 |
# File 'lib/mbanker/crawler.rb', line 29 def extract_action link onclick_value = link.attribute('onclick').value onclick_value.gsub(/\A.*\('/, '').gsub(/'.*\Z/,'') end |
#extract_post_parameters(link) ⇒ Object
34 35 36 37 |
# File 'lib/mbanker/crawler.rb', line 34 def extract_post_parameters link onclick_value = link.attribute('onclick').value onclick_value.gsub(/'/,'').split(',')[3] end |
#extract_text(selector) ⇒ Object
58 59 60 61 |
# File 'lib/mbanker/crawler.rb', line 58 def extract_text selector element = find_first(selector) element ? element.text.strip : '' end |
#extract_texts(selector) ⇒ Object
63 64 65 |
# File 'lib/mbanker/crawler.rb', line 63 def extract_texts selector search(selector).map(&:text).map(&:strip) end |
#find_first(selector) ⇒ Object
54 55 56 |
# File 'lib/mbanker/crawler.rb', line 54 def find_first selector @agent.page.at selector end |
#get_form ⇒ Object
72 73 74 |
# File 'lib/mbanker/crawler.rb', line 72 def get_form @agent.page.form end |
#search(selector) ⇒ Object
50 51 52 |
# File 'lib/mbanker/crawler.rb', line 50 def search selector @agent.page.search(selector) end |
#submit_navigation_form(action, parameters) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/mbanker/crawler.rb', line 39 def action, parameters = @agent.page.form .action = action .__PARAMETERS = parameters .method = 'POST' .submit end |