Last active
September 30, 2016 13:52
-
-
Save 328/7de968c77478c2a75da3203e333a98df to your computer and use it in GitHub Desktop.
0simの今月の使用量を取ってくるrubyスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'mechanize' | |
loginid = '' | |
password = '' | |
agent = Mechanize.new | |
agent.user_agent_alias = 'Mac Safari 4' | |
agent.get('https://www.so-net.ne.jp/retail/u/userMenu/') do |page| | |
login = page.form_with(:name => 'Login') do |form| | |
form.field_with(:name => 'IDToken1').value = loginid | |
form.field_with(:name => 'IDToken2').value = password | |
end.click_button | |
form = login.form_with(:name => "userUsageActionForm") | |
data = form.click_button(form.button_with(:value => 'ご利用状況確認')) | |
doc = Nokogiri::HTML(data.body) | |
text = doc.xpath('//div[@class="guideSignElem"]') | |
perse_text = text.children[1].text.gsub(" ", "").delete("\r\n").delete("\t") | |
use_month = perse_text.split(/[-"MB"]/).reject(&:empty?) | |
if use_month[0].delete("今月のデータ使用量(速報値)") == "" then | |
p 0 | |
else | |
p use_month[0].delete("今月のデータ使用量(速報値)").to_i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment