Created
November 2, 2015 02:46
-
-
Save kyuu1999/aaa682c8ffc808dd214b 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
use strict; | |
use warnings; | |
use feature qw/say/; | |
use HTTP::Request::Common; | |
use LWP::UserAgent; | |
use Time::HiRes; | |
use JSON; | |
my $ua = LWP::UserAgent->new; | |
$ua->timeout(30); | |
$ua->env_proxy; | |
my $tree = new HTML::TreeBuilder::XPath; | |
my $response = $ua->request( GET 'http://promo.ghm.cave.co.jp/gomafes4' ); | |
if ( $response->is_success ) { | |
$tree->parse( $response->decoded_content ); | |
my $key = $tree->findnodes('//p[@id="key"]/span')->pop->as_trimmed_text; | |
while(1){ | |
my $result = $ua->request( | |
POST 'http://promo.ghm.cave.co.jp/gomafes4/count', | |
[ | |
key => $key, | |
count => 50, | |
], | |
Accept => 'application/json, text/javascript, */*; q=0.01', | |
); | |
my $data; | |
eval{ | |
$data = decode_json($result->content); | |
}; | |
$key = $data->{key}; | |
say $data->{count}; | |
Time::HiRes::sleep(0.2); | |
} | |
} | |
else { | |
die $response->status_line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment