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