在http://www.top100.cn上选中自己喜欢的专辑,然后点左侧的 下载此专辑 得到专辑的URL。将该URL当作程序的参数运行,会在当前目录下下载该专辑的所以歌曲。
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $url=$ARGV[0]; my $ua=LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.0.19) Gecko/2010033100 Iceweasel/3.0.6 (Debian-3.0.6-3)"); my $res=$ua->get($url); my %urls=$res->content=~/<td width="200" align="left" class="txt2">.+?<a href="(.+?)">(.+?)<\/a>/sg; foreach (keys %urls){ print "下载 《$urls{$_}》\n"; my $req = HTTP::Request->new(GET => $_); $req->header('Referer', $url); $res=$ua->request($req); open (MP3,">$urls{$_}.mp3"); print MP3 $res->content; close MP3; print "完成!\n"; }