# HG changeset patch # User "Rex Tsai " # Date 1225350017 -28800 # Node ID 5a66fea952fe390aacd55856486bbd31519ae0cd # Parent da0dd597401cd0e3ff05ec969941d7179fbb79e3 implemented a dirty hack to fixed the stupid highscore search function. diff -r da0dd597401c -r 5a66fea952fe Ikariam.pm --- a/Ikariam.pm Wed Oct 29 23:08:38 2008 +0800 +++ b/Ikariam.pm Thu Oct 30 15:00:17 2008 +0800 @@ -50,7 +50,10 @@ $string = $content; } - $self->{doc} = $parser->parse_html_string ($string, { suppress_errors => 1, encoding => 'utf-8' }); + # dirty hack for stupid highScore search function. + $string =~ s/name="searchUser" value=".*?"/name="searchUser" value=""/; + + $self->{doc} = $parser->parse_html_string ($string, { suppress_errors => 1, encoding => 'UTF-8' }); return; } @@ -90,14 +93,11 @@ use strict; use Data::Dumper; use LWP; -# use LWP::Debug qw(+ -conns -trace -debug); -# use LWP::Debug qw(+trace); use HTTP::Cookies; use WWW::Mechanize; use HTML::TagParser; use XML::LibXML qw(:encoding); use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; -# use Time::ParseDate; use POSIX; use utf8; @@ -114,6 +114,7 @@ server => $server, user => $user, pass => $pass, + debug => undef, buildingIDs => { townHall => 0, townhall => 0, @@ -139,6 +140,9 @@ }; + # if debug + # LWP::Debug::level('+conns'); + $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-cookies.txt", autosave => 1)); $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); @@ -171,25 +175,30 @@ my $offset = shift || 0; my %users; - my $res = $self->{mech}->post(sprintf("http://%s/index.php", $self->{server}), [ - highscoreType => $type, - offset => $offset, - searchUser => $user, - view => 'highscore' - ]); + $self->{mech}->get(sprintf("http://%s/index.php?view=highscore&showMe=1", $self->{server})); + my $res = $self->{mech}->submit_form( + form_number => 1, + fields => { + highscoreType => $type, + offset => $offset, + searchUser => $user, + } + ); + my $extractor = new Ikariam::Extractor(content => $res->content); my $result = $extractor->{doc}->find('//table[@class="table01"][2]//tr'); foreach my $tr ( @$result ) { my %user; - my $extractor = new Ikariam::Extractor(content => $tr->toString(1)); + my $extractor = new Ikariam::Extractor(content => $tr->toString(0)); my $href = $extractor->find('//td[@class="action"]/a/@href'); if($href =~ /index\.php\?view=sendMessage&with=(\d+)&oldView=highscore/) { $user{'id'} = $1; - $user{'name'} = $user; + # $user{'name'} = $user; # encoding issue. $user{'name'} = $extractor->find('//td[@class="name"]/text()'); + next if($user{'name'} eq ''); $user{'ally'} = $extractor->find('//td[@class="allytag"]/a/text()'); my $allyHref = $extractor->find('//td[@class="allytag"]/a/@href'); @@ -298,7 +307,17 @@ $info{'owner'} = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="owner"]/text()', $i)); $info{'owner'} =~ s/\s+//g; $info{'ally'} = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="ally"]/a/text()', $i)); - delete($info{'ally'}) if($info{'ally'} eq '-'); + if($info{'ally'} eq '-') { + delete($info{'ally'}) + } else { + my $href = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="ally"]/a/@href', $i)); + # http://s2.ikariam.tw/index.php?view=allyPage&allyId=264&oldView=island&id=569 + if($href =~ /&allyId=(\d+)&/) { + $info{'allyId'} = $1; + } + } + + # Ally Id my $href = $extractor->find(sprintf('//li[@id="cityLocation%s"]//a[@class="messageSend"]/@href', $i)); # ?view=sendMessage&type=0&with=20204&destinationCityId=64165&oldView=island