Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Mojo::Base -strict;
- use Mojo::UserAgent;
- use Mojo::JSON qw(encode_json);
- my %dom = (
- li => 'li.list-item',
- img => 'img.picCore',
- price => 'span.price span.value',
- lazy=>'textarea.lazy-render',
- );
- my $c=1;
- my $item = sub {
- my $li = shift;
- my $img = $li->find($dom{img});
- say encode_json({
- '#'=>$c++,
- #~ img=>$img->attr('src') | $img->attr('image-src'), ??? not work!!!
- img=>$img->attr('src') | $img->attr('image-src'),
- price => $li->find($dom{price})->all_text,
- });
- };
- my $res = Mojo::UserAgent->new->get('http://www.aliexpress.com/wholesale?SearchText=foo')->res;
- $res->dom($dom{li})->each($item);
- Mojo::DOM->new($res->dom($dom{lazy})->all_text)->find($dom{li})->each($item);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement