Changeset 17266

Show
Ignore:
Timestamp:
08/08/08 18:02:03 (5 years ago)
Author:
hidek
Message:

add reply_id and reply_name elements to recent_echo

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/WWW-Mixi-Scraper/trunk/lib/WWW/Mixi/Scraper/Plugin/RecentEcho.pm

    r17253 r17266  
    66use URI; 
    77 
    8 validator {( page => 'is_number' )}; 
     8validator { ( page => 'is_number' ) }; 
    99 
    1010sub scrape { 
    11   my ($self, $html) = @_; 
     11    my ( $self, $html ) = @_; 
    1212 
    13   my $scraper = scraper { 
    14     process 'div.archiveList>table>tr', 
    15       'recents[]' => scraper { 
    16         process '//td[@class="comment"]//div[1]', id => 'HTML'; 
    17         process '//td[@class="comment"]//div[2]', time => 'HTML'; 
    18         process '//td[@class="comment"]//div[3]', name => 'HTML'; 
    19         process '//td[@class="comment"]//div[4]', comment => 'HTML'; 
    20         process '//td[@class="thumb"]//img',      icon => '@src'; 
     13    my $scraper = scraper { 
     14        process 'div.archiveList>table>tr', 'recents[]' => scraper { 
     15            process '//td[@class="comment"]//div[1]', id      => 'HTML'; 
     16            process '//td[@class="comment"]//div[2]', time    => 'HTML'; 
     17            process '//td[@class="comment"]//div[3]', name    => 'HTML'; 
     18            process '//td[@class="comment"]//div[4]', comment => 'HTML'; 
     19            process '//td[@class="thumb"]//img',      icon    => '@src'; 
     20            process 
     21                '//td[@class="comment"]//a[starts-with(@href, "list_echo.pl")]', 
     22                reply_name => [ 'HTML', sub { (/>>(.+)/)[0] } ]; 
     23            process 
     24                '//td[@class="comment"]//a[starts-with(@href, "list_echo.pl")]', 
     25                reply_id => 
     26                [ '@href', sub { (/list_echo.pl\?id=(\d+)\&/)[0] } ]; 
     27 
     28        }; 
    2129    }; 
    22   }; 
    2330 
    24   my $stash = $self->post_process($scraper->scrape(\$html)); 
    25   my $data = $stash->[0] or return $stash; 
    26   $data->{count} = 0; 
    27   foreach my $echo ( @{ $data->{recents} } ) { 
    28       $data->{count}++; 
    29       $echo->{link} = URI->new("http://mixi.jp/view_echo.pl?id=@{[$echo->{id}]}&post_time=@{[$echo->{time}]}"); 
    30   } 
    31   return $stash; 
     31    my $stash = $self->post_process( $scraper->scrape( \$html ) ); 
     32    my $data = $stash->[0] or return $stash; 
     33    $data->{count} = 0; 
     34    foreach my $echo ( @{ $data->{recents} } ) { 
     35        $data->{count}++; 
     36        $echo->{link} 
     37            = URI->new( 
     38            "http://mixi.jp/view_echo.pl?id=@{[$echo->{id}]}&post_time=@{[$echo->{time}]}" 
     39            ); 
     40    } 
     41    return $stash; 
    3242} 
    3343 
     
    5363    recents  => [ 
    5464      { 
    55         link    => 'http://mixi.jp/view_echo.pl?id=xxxx&post_time=xxxx', 
    56         id      => 'xxxx', 
    57         time    => 'yyyymmddhhmmss', 
    58         name    => 'username', 
    59         comment => 'comment', 
     65        link       => 'http://mixi.jp/view_echo.pl?id=xxxx&post_time=xxxx', 
     66        id         => 'xxxx', 
     67        time       => 'yyyymmddhhmmss', 
     68        name       => 'username', 
     69        comment    => 'comment', 
     70        icon       => 'icon', 
     71        reply_name => 'username', 
     72        reply_id   => 'xxxx', 
    6073      }, 
    6174    ],