Skip to content

Instantly share code, notes, and snippets.

@mamantoha
Last active October 6, 2015 04:27
Show Gist options
  • Select an option

  • Save mamantoha/2935856 to your computer and use it in GitHub Desktop.

Select an option

Save mamantoha/2935856 to your computer and use it in GitHub Desktop.
Current balance my.kyivstar.net
# encoding: utf-8
require 'pp'
require 'mechanize'
require 'nokogiri'
user = '103900'
password = '***'
agent = Mechanize.new do |a|
a.follow_meta_refresh = true
a.ssl_version = 'SSLv3'
end
page = agent.get('https://my.kyivstar.ua/tbmb/login/show.do')
login_form = page.form_with(:action => '/tbmb/login/perform.do')
login_form.user = user
login_form.password = password
show_page = agent.submit(login_form)
puts show_page.uri.to_s == "https://my.kyivstar.ua/tbmb/disclaimer/show.do" ? "Login successful" : abort("Login failure")
show_page_html = show_page.body.encode('utf-8', 'cp1251')
doc = Nokogiri::HTML(show_page_html)
rows = doc.xpath("//td[@id='mainContentBlock']/table/tr")
details = rows.collect do |row|
detail = {}
[
[:title, 'td[1]'],
[:data, 'td[2]'],
].collect do |name, xpath|
value = row.at_xpath(xpath)
if value.class == Nokogiri::XML::Element
detail[name] = value.children.text.strip.gsub(/\s+/, ' ')
end
end
detail
end
pp details
balance = details.find{ |e| e[:title] == "Поточний баланс:" }
bonus = details.find{ |e| e[:title] == "Баланс:" }
puts "#{balance[:title]}: #{balance[:data]} (#{bonus[:data]})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment