Mercurial > eagle-eye
comparison Ikariam.pm @ 150:fab1593cadf1
fixed the combat reading issue.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sat, 01 Nov 2008 03:52:09 +0800 |
parents | b23077d597b0 |
children | 637314cc57ed |
comparison
equal
deleted
inserted
replaced
149:97dfcc0d1e3f | 150:fab1593cadf1 |
---|---|
35 $self->parse($conf{'content'}) if(defined($conf{'content'})); | 35 $self->parse($conf{'content'}) if(defined($conf{'content'})); |
36 | 36 |
37 return $self; | 37 return $self; |
38 } | 38 } |
39 | 39 |
40 # parse($Content); | |
41 sub parse { | 40 sub parse { |
42 my ($self, $content) = @_; | 41 my ($self, $content) = @_; |
43 my $string; | 42 my $string; |
44 my $parser = XML::LibXML->new('1.0','UTF-8'); | 43 my $parser = XML::LibXML->new('1.0','UTF-8'); |
45 | 44 |
66 my $result = $self->{doc}->find($query); | 65 my $result = $self->{doc}->find($query); |
67 | 66 |
68 return undef unless defined($result); | 67 return undef unless defined($result); |
69 | 68 |
70 if ( $result->isa( 'XML::LibXML::NodeList' ) ) { | 69 if ( $result->isa( 'XML::LibXML::NodeList' ) ) { |
71 return () if($result->size() == 0); | 70 if($result->size() == 0) { |
71 return undef unless wantarray; | |
72 return (); | |
73 } | |
72 foreach ( @$result ) { | 74 foreach ( @$result ) { |
73 # $_ is XML::LibXML::Element, XML::LibXML::Node | 75 # $_ is XML::LibXML::Element, XML::LibXML::Node |
74 my $literal = $_->to_literal(); | 76 my $literal = $_->to_literal(); |
75 utf8::encode($literal); | 77 utf8::encode($literal); |
76 # warn $_->toString(1) , "\n"; | 78 # warn $_->toString(1) , "\n"; |
575 | 577 |
576 $report{attacker} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//th[@class="attackers"]'); | 578 $report{attacker} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//th[@class="attackers"]'); |
577 $report{defender} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//th[@class="defenders"]'); | 579 $report{defender} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//th[@class="defenders"]'); |
578 $report{winner} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//td[@class="winner"]'); | 580 $report{winner} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//td[@class="winner"]'); |
579 | 581 |
582 # the combat we win! | |
580 $report{targetCity} = $extractor->find('//div[@id="troopsReport"]/div/h3/a/text()'); | 583 $report{targetCity} = $extractor->find('//div[@id="troopsReport"]/div/h3/a/text()'); |
581 my $href = $extractor->find('//div[@id="troopsReport"]/div/h3/a/@href'); | 584 my $href = $extractor->find('//div[@id="troopsReport"]/div/h3/a/@href'); |
582 # $report{targetCity} = $extractor->find('//td[@class="battle"]/a/text()'); | 585 if(!defined($href)) { |
583 # my $href = $extractor->find('//td[@class="battle"]/a/@href'); | 586 # the combat we lost! |
587 $report{targetCity} = $extractor->find('//td[@class="battle"]/a/text()'); | |
588 $href = $extractor->find('//td[@class="battle"]/a/@href'); | |
589 } | |
584 | 590 |
585 if($href =~ /index\.php\?view=island&id=(\d+)&selectCity=(\d+)/) { | 591 if($href =~ /index\.php\?view=island&id=(\d+)&selectCity=(\d+)/) { |
586 $report{island} = $1; | 592 $report{island} = $1; |
587 $report{city} = $2; | 593 $report{city} = $2; |
588 } else { | 594 } else { |
595 warn($href); | |
589 warn ("can not read combat reprot $combatId"); | 596 warn ("can not read combat reprot $combatId"); |
590 warn ($href); | |
591 return undef; | 597 return undef; |
592 } | 598 } |
593 $report{gold} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="gold"]'); | 599 $report{gold} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="gold"]'); |
594 $report{wood} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="wood"]'); | 600 $report{wood} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="wood"]'); |
595 $report{crystal} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="glass"]'); | 601 $report{crystal} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="glass"]'); |