comparison Ikariam.pm @ 110:279a000eb3b0

fixed encoding issue of LibXML
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 29 Oct 2008 17:49:08 +0800
parents 31803acb9c5f
children 5a66fea952fe
comparison
equal deleted inserted replaced
108:d3bece9b06b2 110:279a000eb3b0
39 39
40 # parse($Content); 40 # parse($Content);
41 sub parse { 41 sub parse {
42 my ($self, $content) = @_; 42 my ($self, $content) = @_;
43 my $string; 43 my $string;
44 my $parser = XML::LibXML->new('1.0','utf-8'); 44 my $parser = XML::LibXML->new('1.0','UTF-8');
45 45
46 if($self->{gzip} == 1) { 46 if($self->{gzip} == 1) {
47 gunzip \$content => \$string 47 gunzip \$content => \$string
48 or die "gunzip failed: $GunzipError\n"; 48 or die "gunzip failed: $GunzipError\n";
49 } else { 49 } else {
50 $string = $content; 50 $string = $content;
51 } 51 }
52 52
53 $self->{doc} = $parser->parse_html_string ($string, { suppress_errors => 1 }); 53 $self->{doc} = $parser->parse_html_string ($string, { suppress_errors => 1, encoding => 'utf-8' });
54 return; 54 return;
55 } 55 }
56 56
57 # find($XPathQuery); 57 # find($XPathQuery);
58 sub find { 58 sub find {
186 186
187 my $href = $extractor->find('//td[@class="action"]/a/@href'); 187 my $href = $extractor->find('//td[@class="action"]/a/@href');
188 if($href =~ /index\.php\?view=sendMessage&with=(\d+)&oldView=highscore/) { 188 if($href =~ /index\.php\?view=sendMessage&with=(\d+)&oldView=highscore/) {
189 $user{'id'} = $1; 189 $user{'id'} = $1;
190 $user{'name'} = $user; 190 $user{'name'} = $user;
191 $user{'name'} = $extractor->find('//td[@class="name"]'); 191 # encoding issue.
192 $user{'name'} = $extractor->find('//td[@class="name"]/text()');
192 193
193 $user{'ally'} = $extractor->find('//td[@class="allytag"]/a/text()'); 194 $user{'ally'} = $extractor->find('//td[@class="allytag"]/a/text()');
194 my $allyHref = $extractor->find('//td[@class="allytag"]/a/@href'); 195 my $allyHref = $extractor->find('//td[@class="allytag"]/a/@href');
195 if($allyHref =~ /\?view=allyPage&oldView=highscore&allyId=(\d+)/) { 196 if($allyHref =~ /\?view=allyPage&oldView=highscore&allyId=(\d+)/) {
196 $user{'allyId'} = $1; 197 $user{'allyId'} = $1;