top500 part3 检测文件的类型及大小

| 暂无评论 | 暂无引用通告

-->

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");

my $response=$ua->request($request);
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的前端

功能简介:通过用户从页面的表单提供的歌手名或歌曲名,从百度解析歌曲地址。

暂无引用通告

发送引用通告网址: http://supersun.info/mt/mt-tb.cgi/614
如果您想引用这篇日记到您的Blog,请复制上面的链接,放置到您发表文章时的相应界面中。

发表评论

最新资源

  • IMG_1437.JPG
  • line.png
  • bar.png
  • perl_calander.jpg

关于此日记

此日记由 supersun 发表于 2007年4月19日 17:33

此Blog上的上一篇日记简单的web客户机

此Blog上的下一篇日记简单的cgi脚本

首页归档页可以看到最新的日记和所有日记。