Created
September 29, 2011 01:43
-
-
Save cho45/1249785 to your computer and use it in GitHub Desktop.
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
#!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, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment