Advertisement
Guest User

Untitled

a guest
Oct 28th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. use Mojo::Base -strict;
  2. use Mojo::UserAgent;
  3. use Mojo::JSON qw(encode_json);
  4. my %dom = (
  5. li => 'li.list-item',
  6. img => 'img.picCore',
  7. price => 'span.price span.value',
  8. lazy=>'textarea.lazy-render',
  9. );
  10.  
  11. my $c=1;
  12. my $item = sub {
  13. my $li = shift;
  14. my $img = $li->find($dom{img});
  15. say encode_json({
  16. '#'=>$c++,
  17. #~ img=>$img->attr('src') | $img->attr('image-src'), ??? not work!!!
  18. img=>$img->attr('src') | $img->attr('image-src'),
  19. price => $li->find($dom{price})->all_text,
  20. });
  21.  
  22. };
  23.  
  24.  
  25. my $res = Mojo::UserAgent->new->get('http://www.aliexpress.com/wholesale?SearchText=foo')->res;
  26. $res->dom($dom{li})->each($item);
  27. Mojo::DOM->new($res->dom($dom{lazy})->all_text)->find($dom{li})->each($item);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement