Mercurial > eagle-eye
comparison Ikariam.pm @ 92:bcd2e32cfabb
fixed the user name encoding issue.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 26 Oct 2008 22:56:16 +0800 |
parents | 53c87400183f |
children | 65c102183458 |
comparison
equal
deleted
inserted
replaced
91:53c87400183f | 92:bcd2e32cfabb |
---|---|
66 | 66 |
67 if ( $result->isa( 'XML::LibXML::NodeList' ) ) { | 67 if ( $result->isa( 'XML::LibXML::NodeList' ) ) { |
68 return () if($result->size() == 0); | 68 return () if($result->size() == 0); |
69 foreach ( @$result ) { | 69 foreach ( @$result ) { |
70 # $_ is XML::LibXML::Element, XML::LibXML::Node | 70 # $_ is XML::LibXML::Element, XML::LibXML::Node |
71 my $literal = $_->to_literal() , "\n"; | 71 my $literal = $_->to_literal(); |
72 utf8::encode($literal); | 72 utf8::encode($literal); |
73 # warn $_->toString(1) , "\n"; | 73 # warn $_->toString(1) , "\n"; |
74 return $literal unless wantarray; | 74 return $literal unless wantarray; |
75 push( @$out, $literal); | 75 push( @$out, $literal); |
76 } | 76 } |
160 my $extractor = new Ikariam::Extractor(content => $res->content); | 160 my $extractor = new Ikariam::Extractor(content => $res->content); |
161 my $result = $extractor->{doc}->find('//table[@class="table01"][2]//tr'); | 161 my $result = $extractor->{doc}->find('//table[@class="table01"][2]//tr'); |
162 foreach my $tr ( @$result ) { | 162 foreach my $tr ( @$result ) { |
163 my %user; | 163 my %user; |
164 | 164 |
165 my $href = $tr->find('//td[@class="action"]/a/@href'); | 165 $extractor->{doc} = $tr; |
166 my $href = $extractor->find('//td[@class="action"]/a/@href'); | |
166 if($href =~ /index\.php\?view=sendMessage&with=(\d+)&oldView=highscore/) { | 167 if($href =~ /index\.php\?view=sendMessage&with=(\d+)&oldView=highscore/) { |
167 $user{'id'} = $1; | 168 $user{'id'} = $1; |
168 $user{'name'} = $tr->find('//td[@class="name"]/text()'); | 169 # $user{'name'} = $extractor->find('//td[@class="name"]'); |
169 $user{'ally'} = ($tr->find('//td[@class="allytag"]/a/text()'))[0]->to_literal(); | 170 $user{'name'} = $user; |
170 my $allyHref = $tr->find('//td[@class="allytag"]/a/@href'); | 171 |
172 $user{'ally'} = $extractor->find('//td[@class="allytag"]/a/text()'); | |
173 my $allyHref = $extractor->find('//td[@class="allytag"]/a/@href'); | |
171 if($allyHref =~ /\?view=allyPage&allyId=(\d+)/) { | 174 if($allyHref =~ /\?view=allyPage&allyId=(\d+)/) { |
172 $user{'allyId'} = $1; | 175 $user{'allyId'} = $1; |
173 } | 176 } |
174 $user{$type} = $tr->find('//td[@class="score"]/text()'); | 177 $user{$type} = $extractor->find('//td[@class="score"]/text()'); |
175 $user{$type} =~ s/,//g; | 178 $user{$type} =~ s/,//g; |
176 | |
177 # converting data type and encoding. | |
178 foreach(keys(%user)) { utf8::encode($user{$_}); } | |
179 $users{$user{'id'}} = \%user; | 179 $users{$user{'id'}} = \%user; |
180 } | 180 } |
181 } | 181 } |
182 return \%users; | 182 return \%users; |
183 } | 183 } |