批量下载歌曲TOP500
时间:2006-04-17 来源:coldrainsunc
[root@supersun perl]# cat getindex.pl
#!/usr/bin/perl -w
#function:get the index ;
#useage:
# getindex.pl filename url
use strict;
use LWP::Simple;
my $file=shift;
my $url=shift;
my $count=get $url;
open HD,'>',$file;
print HD $count;
close HD;
得到文件filename其中的内容为web页的内容;
如:
[root@supersun perl]# ./getindex.pl filename http://list.mp3.baidu.com/topso/mp3topsong.html#top2
下面我们再来解析文件filename
[root@supersun perl]# cat link.pl
#!/usr/bin/perl -w
use strict;
my $file=shift;
my @link;
open HD,$file;
my @count=<HD>;
my %result;
foreach my $util (@count)
{
if($util =~ m{http://mp3.baidu.com/} and $util =~ m|<td|)
{
$util=~ s|<td.*?>||;
my @hello=split ' ',$util;
shift @hello;
$hello[1] =~ s|target.*?>||g;
$hello[1] =~ s|</a>||;
$hello[0] =~ s/(href=|")//g;
$result{@hello[1]}=$hello[0];
}
}
foreach my $key (keys %result)
{
print "Key:$key\nLink:$result{$key}\n";
}
运行:
[root@supersun perl]# ./link.pl filename
部分结果如下:
Key:大女人
Link:http://mp3.baidu.com/m?tn=baidump3&ct=134217728&lm=-1&li=500&word=%B4%F3%C5%AE%C8%CB+%D5%C5%D3%EE
Key:娃娃
Link:http://mp3.baidu.com/m?tn=baidump3&ct=134217728&lm=-1&li=500&word=%CD%DE%CD%DE+%D5%C5%C9%D8%BA%AD
Key:星晴
Link:http://mp3.baidu.com/m?tn=baidump3&ct=134217728&lm=-1&li=500&word=%D0%C7%C7%E7+%D6%DC%BD%DC%C2%D7
此时,我们已经得到歌曲的名字及相应的搜地址了,下面的工作就是下载相应的mp3文件,待续。。。。。。。
#!/usr/bin/perl -w
#function:get the index ;
#useage:
# getindex.pl filename url
use strict;
use LWP::Simple;
my $file=shift;
my $url=shift;
my $count=get $url;
open HD,'>',$file;
print HD $count;
close HD;
得到文件filename其中的内容为web页的内容;
如:
[root@supersun perl]# ./getindex.pl filename http://list.mp3.baidu.com/topso/mp3topsong.html#top2
下面我们再来解析文件filename
[root@supersun perl]# cat link.pl
#!/usr/bin/perl -w
use strict;
my $file=shift;
my @link;
open HD,$file;
my @count=<HD>;
my %result;
foreach my $util (@count)
{
if($util =~ m{http://mp3.baidu.com/} and $util =~ m|<td|)
{
$util=~ s|<td.*?>||;
my @hello=split ' ',$util;
shift @hello;
$hello[1] =~ s|target.*?>||g;
$hello[1] =~ s|</a>||;
$hello[0] =~ s/(href=|")//g;
$result{@hello[1]}=$hello[0];
}
}
foreach my $key (keys %result)
{
print "Key:$key\nLink:$result{$key}\n";
}
运行:
[root@supersun perl]# ./link.pl filename
部分结果如下:
Key:大女人
Link:http://mp3.baidu.com/m?tn=baidump3&ct=134217728&lm=-1&li=500&word=%B4%F3%C5%AE%C8%CB+%D5%C5%D3%EE
Key:娃娃
Link:http://mp3.baidu.com/m?tn=baidump3&ct=134217728&lm=-1&li=500&word=%CD%DE%CD%DE+%D5%C5%C9%D8%BA%AD
Key:星晴
Link:http://mp3.baidu.com/m?tn=baidump3&ct=134217728&lm=-1&li=500&word=%D0%C7%C7%E7+%D6%DC%BD%DC%C2%D7
此时,我们已经得到歌曲的名字及相应的搜地址了,下面的工作就是下载相应的mp3文件,待续。。。。。。。
相关阅读 更多 +
排行榜 更多 +