-->
top500 part1 的功能:解析出百度top500的排名数据
top500 part2 的功能:根据传给脚本歌手名 歌曲名从百度获得数据并解析出mp3文件的下载地址
而part3的功能就是检测这些链接的有效性,及文件的大小以获得完整的歌曲文件。
#!/usr/bin/perl
#验证文件的类型和大小
use warnings;
use strict;
use LWP::UserAgent;
use HTTP::Request;
my $url=shift;
#建立一个请求对象
my $request= new HTTP::Request ( HEAD => $url );
#建立一个用户代理
my $ua= new LWP::UserAgent;
$ua->agent("Perl_client/1.0(perl $],libwww-perl-$LWP::VERSION,$^O");
if($response->is_success){
my ($type,$length)=($response->header( 'Content-Type' ),$response->header( 'Content-Length' ));
print "文件类型:$type\n文件大小:$length\n";
}else{
print "Error:".$response->status_line."\n";
}
此处我们学习一下lwp的使用,
过程:
建立一个http请求 模块: HTTP::Request 此处只要得文件类型和文件的大小,所有我们使用方法head
建立一个用户代理,相当一个浏览器,模块:LWP::UserAgent 生成一个用户代理后我们对其进行一下设置,可以用perldoc LWP::UserAgent查看其提供的方法
使 用用户代理将http请求发送出去,这样我们就得到一个http响应,通过这个http响应,我们使用HTTP::Response提供的方法我们就可以 得到文件的大小及结果了,另外如果用其他需求我们可以用命令perldoc HTTP::Response来查看模块提供的其他方法。
模块使用举例:
[root@supersun my]# ./top500.2.pl 张韶涵 我的最爱
http://61.145.124.112/Music2/mp3
http://61.145.124.112/Music2/mp3
http://gem.fushikang.cn/mp3
http://gem.fushikang.cn/mp3
http://ccd.top666.cn/mp3
http://www.sqmusic.net/UpLoadFile1/200732375868569.mp3
http://www.sqmusic.net/UpLoadFile1/200732375868569.mp3
http://www.whjy.net/Upload/ArtilceP1/20050712084508.mp3
http://www.whjy.net/Upload/ArtilceP1/20050712084508.mp3
http://file.mip360.com/mobile360/10441/29209/zuiai.mp3
http://file.mip360.com/mobile360/10441/29209/zuiai.mp3
http://61.145.124.106/Music2/mp3
http://61.145.124.106/Music2/mp3
http://61.145.124.106/Music3/mp3
http://61.145.124.106/Music3/mp3
http://www.51588888.com/mp3
http://www.51588888.com/mp3
http://www5.joyes.com/upload_rings/mp3
http://www5.joyes.com/upload_rings/mp3
http://www.886l.com/ccmms/mp3
http://www.886l.com/ccmms/mp3
http://219.136.248.230/Music1/mp3
http://219.136.248.230/Music1/mp3
http://file.ring163.com/mp3
http://file.ring163.com/mp3
http://219.136.248.230/Music2/mp3
http://219.136.248.230/Music2/mp3
http://219.136.248.230/Music3/mp3
http://219.136.248.230/Music3/mp3
http://61.145.124.118/Music3/mp3
http://61.145.124.118/Music3/mp3
http://res.caishow.com/Caix/1/Ring/5291735421316_test.mp3
http://res.caishow.com/Caix/1/Ring/5291735421316_test.mp3
http://61.145.124.118/Music1/mp3
http://61.145.124.118/Music1/mp3
http://ring.my12530.com/mp3
http://ring.my12530.com/mp3
http://www.92box.com/mp3
http://www.92box.com/mp3
http://222.73.231.162/vadown/audio/200611/116364773303181.mp3
http://222.73.231.162/vadown/audio/200611/116364773303181.mp3
http://file.zhangxiu.com/source/7/5/8/5/7585cbUrx1GE.mp3
http://file.zhangxiu.com/source/7/5/8/5/7585cbUrx1GE.mp3
http://mp3
http://mp3
http://ring.caishow.com/mp3
http://ring.caishow.com/mp3
http://ring.caishow.com/mp3
http://ring.caishow.com/mp3
[root@supersun my]# ./top500.3.pl http://res.caishow.com/Caix/1/Ring/5291735421316_test.mp3
文件类型:audio/mpeg
文件大小:101760
脚本的下一部分是做一个简单的baidu mp3的前端
功能简介:通过用户从页面的表单提供的歌手名或歌曲名,从百度解析歌曲地址。

发表评论