public
Created

  • Download Gist
auispackets.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!perl
 
use utf8;
use strict;
use warnings;
 
use WWW::Mechanize;
use Encode;
use Config::Pit;
use HTML::TreeBuilder::XPath;
 
my $config = pit_get("cs.kddi.com", require => {
"username" => "your username on example",
"password" => "your password on example"
});
 
my $mech = WWW::Mechanize->new;
$mech->agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1");
 
$mech->get('https://cs.kddi.com/');
$mech->submit_form(
form_name => 'auLogin',
fields => {
UserID => $config->{username},
Password => $config->{password},
}
);
 
$mech->submit_form( form_name => 'recentcharge');
$mech->submit_form( form_name => 'formIsPacketSu');
 
my $html = decode('Shift_JIS', $mech->res->content);
my ($details) = ($html =~ m{<h4>日毎の内訳</h4>([\s\S]+?)</table>});
my $matched = [ $details =~ m{\((\d\d\d\d)/(\d\d)/(\d\d)\)[\s\S]*?([\d,]+)\s*パケット}g ];
 
while (my ($year, $month, $day, $packets) = splice @$matched, 0, 4) {
$packets =~ s{,}{}g;
 
use Data::Dumper;
warn Dumper +{
year => $year,
month => $month,
day => $day,
packets => $packets,
};
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.