Advertisement
Guest User

Untitled

a guest
Sep 1st, 2012
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.72 KB | None | 0 0
  1. #requirement
  2. #if not installed: sudo cpan install Web:Scraper
  3.  
  4. #example call:
  5. perl ./spotify.pl '<iframe src="https://embed.spotify.com/?uri=spotify:track:2qpmEFEoc6bVpYhc4Lp5Uo" width="300" height="380" frameborder="0" allowtransparency="true"></iframe>
  6. <iframe src="https://embed.spotify.com/?uri=spotify:track:28TcG73tbc4iGrGBFjiBnR" width="300" height="380" frameborder="0" allowtransparency="true"></iframe>'
  7.  
  8. //CODE
  9. use strict;
  10. use URI;
  11. use Web::Scraper;
  12.  
  13. #init
  14. my @songs=();
  15. #scraper
  16. my $data = scraper {
  17.  # we will save the urls from the teams
  18.  process "ul.track-info>li.track-title", 'titles[]' => 'TEXT';
  19.  process "ul.track-info>li.artist", 'artists[]' => 'TEXT';
  20. };
  21.  
  22. #loop over infput
  23. foreach ($ARGV[0]=~/<iframe src="(.*)" width="300" height="380" frameborder="0" allowtransparency="true"><\/iframe>/g){
  24.  
  25. # scrape the data
  26. my $res = $data->scrape(URI->new($_));
  27.  
  28. push(@songs,$res->{titles}[0] . " " . $res->{artists}[0]);
  29.  
  30. }
  31. print join("\n",@songs),"\n";
  32. ~                                                                                                                                                      
  33. ~                                                                                                                                                      
  34. ~                                                                                                                                                      
  35. ~                                                                                                                                                      
  36. ~                                                                                                                                                      
  37. ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement