| 36 | | my $self = shift; |
| 37 | | my $url = URI->new($self->{url}); |
| 38 | | my $result = scraper { |
| 39 | | process '/html/body/table/tr/td[3]/table[3]/tr/td/table/tr/td[5]/a', |
| 40 | | 'txt_list' => '@href'; |
| 41 | | process '/html/body/table/tr/td[3]/table[3]/tr/td/table/tr/td[6]/a', |
| 42 | | 'img_list' => '@href'; |
| 43 | | process '/html/body/table/tr/td/table/tr/td/table/tr/td[2]/a', |
| 44 | | 'title[]' => 'TEXT', |
| 45 | | 'link[]' => '@href'; |
| 46 | | }->scrape($self->_fetch($url)); |
| | 28 | my $self = shift; |
| | 29 | my $result = scraper { |
| | 30 | process '/html/body/table/tr/td[3]/table[3]/tr/td/table/tr/td[5]/a', |
| | 31 | 'txt_list' => '@href'; |
| | 32 | process '/html/body/table/tr/td[3]/table[3]/tr/td/table/tr/td[6]/a', |
| | 33 | 'img_list' => '@href'; |
| | 34 | process '/html/body/table/tr/td/table/tr/td/table/tr/td[2]/a', |
| | 35 | 'title[]' => 'TEXT', |
| | 36 | 'link[]' => '@href'; |
| | 37 | }->scrape($self->_fetch($self->{url})); |
| 48 | | foreach my $key (keys %$result){ |
| 49 | | if($key =~ /^(title|link)$/){ |
| 50 | | foreach my $i (@{$result->{$key}}){ |
| 51 | | push(@{$self->{$1}}, $i); |
| 52 | | } |
| 53 | | }else{ |
| 54 | | $self->set($key, $self->_delete_space($result->{$key})); |
| 55 | | } |
| 56 | | } |
| 57 | | } |
| 58 | | |
| 59 | | sub _delete_space { |
| 60 | | my ($self, $str) = @_; |
| 61 | | $str =~ s/^\s*(.*?)\s*$/$1/; |
| 62 | | return $str; |
| 63 | | } |
| 64 | | |
| 65 | | sub _fetch { |
| 66 | | my $self = shift || return; |
| 67 | | my $url = shift || return; |
| 68 | | my $page = ''; |
| 69 | | if($self->{opt}->{fetch}){ |
| 70 | | $page = URI::Fetch->fetch( |
| 71 | | $url, |
| 72 | | UserAgent => $self->{opt}->{ua}, |
| 73 | | Cache => $self->{opt}->{fetch}->{cache}, |
| 74 | | NoNetwork => $self->{opt}->{fetch}->{nonetwork}, |
| 75 | | ); |
| 76 | | }else{ |
| 77 | | $page = URI::Fetch->fetch( |
| 78 | | $url, |
| 79 | | UserAgent => $self->{opt}->{ua}, |
| 80 | | ); |
| 81 | | } |
| 82 | | return encode('utf8', decode('euc-jp', $page->content)); |
| | 39 | foreach my $key (keys %$result){ |
| | 40 | if($key =~ /^(title|link)$/){ |
| | 41 | foreach my $i (@{$result->{$key}}){ |
| | 42 | push(@{$self->{$1}}, $i); |
| | 43 | } |
| | 44 | }else{ |
| | 45 | $self->set($key, $self->_rm_space($result->{$key})); |
| | 46 | } |
| | 47 | } |