Created
September 24, 2015 10:01
-
-
Save yasu47b/b2fa3fb094057843dfda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use feature 'say'; | |
use Mojo::DOM; | |
use Mojo::UserAgent; | |
use Data::Dumper; | |
use Encode; | |
my $ua = Mojo::UserAgent->new; | |
my @tatal_reviews = (); | |
my @page_reviews = (); | |
my $page; | |
# get one page info | |
$page = &extract_review(url =>'some_url'); | |
say Dumper \@page_reviews; | |
say $#page_reviews+1; | |
sub extract_review(){ | |
my $args = {@_}; | |
my $url = $args->{url}; | |
if ( not defined $url ){ | |
return undef; | |
} | |
my $output = []; | |
my $res = $ua->get($url)->res; | |
for my $e ($res->dom('div#REVIEWS > div')->each) { | |
my $review_info = {}; | |
if ( defined $e->{id} && $e->{id} =~ /review/i){ | |
$review_info->{id} = $e->{id} if $e->{id}; | |
$review_info->{location} = $e->at(".location")->text if ( $e->at(".location") ); | |
$review_info->{partial_entry} = $e->at(".partial_entry")->text if ($e->at(".partial_entry")); | |
} | |
push @$output, $review_info if ( keys %$review_info ); | |
} | |
my $next_url = $res->dom("a.nav.next.rndBtn.rndBtnGreen.taLnk")->[0]->attr('href'); | |
if (wantarray){ | |
return @$output; | |
} else { | |
return { reviews => $output, nex_url => $next_url}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment