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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
use strict; use warnings; use Data::Dumper; use Text::Trim; use HTML::Query 'Query'; use WWW::Mechanize;
our $login_url = "http://www.example.com/signin"; our $home_url = "http://www.example.com/"; our $award_url = "http://www.example.com/mission/daily"; our $mechanize = WWW::Mechanize->new();
sub println { print map{"$_\n"} @_; }
sub login_info { $mechanize->get($login_url);
my @elements = Query(text => $mechanize->content(), "input[name=once]")->get_elements(); my $once = $elements[0]->attr('value');
return { next => '/', u => 'username', p => 'password', once => $once }; }
sub do_award { my $login_info = login_info();
$mechanize->post($login_url, $login_info);
if ($mechanize->cookie_jar->as_string !~ /auth/) { println("Login fail"); exit(0); }
$mechanize->get($home_url);
if ($mechanize->find_link(url => "/balance") == undef) { println("Get money fail"); exit(0); }
my @balance_elements = Query(text => $mechanize->content(), "a.balance_area")->get_elements(); my @balance_content = @{$balance_elements[0]->content};
println('Your money: ' . trim($balance_content[0]) . ', ' . trim($balance_content[2]));
if ($mechanize->find_link(url => "/mission/daily") == undef) { println("You haved got the award."); exit(0); }
$mechanize->get($award_url);
my @click_elements = Query(text => $mechanize->content(), "input[type='button']")->get_elements(); my $onclick = $click_elements[0]->attr('onclick'); my ($location) = ($onclick =~ m/location.href = \'\/(.*)\';/); my $click_url = $home_url . $location;
$mechanize->get($award_url);
my @message_elements = Query(text => $mechanize->content(), "div.message")->get_elements(); my $message = @{$message_elements[0]->content}[0];
println($message); }
do_award();
|