Skip to content

Instantly share code, notes, and snippets.

@cho45
Created September 29, 2011 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cho45/1249785 to your computer and use it in GitHub Desktop.
Save cho45/1249785 to your computer and use it in GitHub Desktop.
#!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