当前位置: 首页 > 图文教程 > 网络编程 > ASP > 使用Flash DownLoad编写采集器(之突破防盗连下载音乐文件)

ASP
ASP正则表达式技巧
ASP Access实现网站计数器(访问量)
ASP新闻分页,将一篇过长的文章分页,生成静态页面
一些关于asp 购物车的想法
一个sql查询器,自动画表格填字段
ASP实现文件直接下载的代码
把网页中的(电话,qq等数字)生成图片的ASP程序
asp长文章用分页符来分页显示
Asp函数介紹(37个常用函数)
ASP中的面向对象类
分页实现方法的性能比较
asp ajax跨域提交数据
asp修改文件和文件夹的名字的代码
ASP 多关键词查询实例代码
asp被杀毒软件误删的解决方法
asp 多关键词搜索的简单实现方法
asp 根据IP地址自动判断转向分站的代码
asp dictionary对象的用法
ASP 千万级数据分页的存储过程
ASP隐藏真实文件的下载功能实现代码

ASP 中的 使用Flash DownLoad编写采集器(之突破防盗连下载音乐文件)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 165 ::
收藏到网摘: n/a

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Flash DownLoad 下载控件示例</title>
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<meta http-equiv="MSThemeCompatible" content="Yes">
<style type="text/css">
body {
scrollbar-base-color: #F5FBFF;
scrollbar-arrow-color: #86B9D6;
font: 12px Tahoma, Verdana;
background-color: #FFFFFF;
color: #333333;
}
table {
font: 12px Tahoma, Verdana;
color: #333333;
empty-cells: show;
border-collapse: separate !important;
border-collapse: collapse;
}
input, select, textarea {
font: 12px Tahoma, Verdana;
color: #333333;
font-weight: normal;
background-color: #F5FBFF;
border: 1px solid #7AC4EA;
}
input {
height: 21px;
}
a {
text-decoration: none;
color: #154BA0;
}
a:hover {
text-decoration: underline;
}
.checkbox, .radio {
border: 0px;
background: none;
vertical-align: middle;
height: 16px;
}
</style>
</head>
<BODY>
<Script Language="JavaScript">
/********************************************************
* ProgressBar class
* @author null
* @param width - width of progress bar
* @param height - height of progress bar
* @param fgColor - fgColor of progress bar
* @param bgColor - bgColor of progress bar
* @param borderColor - borderColor of progress bar
the rule is the same border-color of CSS
/********************************************************/
function ProgressBar(width,height,fgColor,bgColor,borderColor){
if(borderColor==undefined){
bgColor = "threedlightshadow";
fgColor = "highlight";
borderColor = "buttonshadow window window buttonshadow";
}
else if(borderColor==undefined&&fgColor==undefined&&bgColor==undefined){
bgColor = "threedlightshadow";
fgColor = "highlight";
borderColor = "buttonshadow window window buttonshadow";
}
percent = 0.0; //initialize to zero
fontSize = Math.ceil(height/2)+1;
font_bt = "<table width=100% height=100% cellpadding=0 cellspacing=0 style='font:bold "+fontSize+"px Arial;color:"+bgColor+";text-align:center;vertical-align:center;'><tr><td>"+parseInt(percent*100)+" %</td></tr></table>";
font_ft = "<table width=100% height=100% cellpadding=0 cellspacing=0 style='font:bold "+fontSize+"px Arial;color:"+fgColor+";text-align:center;vertical-align:center;'><tr><td>"+parseInt(percent*100)+" %</td></tr></table>";
squares = "";
for(var i=0;;i++){
var left = width-2-i*(height/2+1);
//alert(left);
if(left>=height/2+1){
squares += "<span style='background-color:"+fgColor+";width:"+height/2+"px;height:"+(height-2)+";margin-right:1px;'></span>";
}
else if(left>=1){
squares += "<span style='background-color:"+fgColor+";width:"+left+"px;height:"+(height-2)+";margin:0px;'></span>";
}
else
break;
}
//position:absolute;
str = "<span id=progress_bg style='width:"+width+"px;height:"+height+"px;background-color:"+bgColor+";border:1px solid;border-color:"+borderColor+"'>"; //"+fgColor+" #transparent
str += " <span id=progress_fg style='position:absolute;width:100%;height:100%;clip:rect(0,"+parseInt(percent*100)+"%,100%,0);background-color:"+fgColor+";font-size:0px;line-height:0px;'>";
str += squares;
str += " </span>";
str += " <span id=progress_bt style='position:absolute;z-index:8;width:100%;height:100%;background-color:#transparent;clip:rect(0,"+parseInt(percent*100)+"%,100%,0);text-align:center;'>";
str += font_bt;
str += " </span>";
str += " <span id=progress_ft style='position:absolute;z-index:9;width:100%;height:100%;background-color:#transparent;clip:rect(0,100%,100%,"+parseInt(percent*100)+"%);text-align:center;'>";
str += font_ft;
str += " </span>";
str += "</span>";
document.write(str);

function update(){
font_bt = "<table width=100% height=100% cellpadding=0 cellspacing=0 style='font:bold "+fontSize+"px Arial;color:"+bgColor+";text-align:center;vertical-align:center;'><tr><td>"+parseInt(percent*100)+" %</td></tr></table>";
font_ft = "<table width=100% height=100% cellpadding=0 cellspacing=0 style='font:bold "+fontSize+"px Arial;color:"+fgColor+";text-align:center;vertical-align:center;'><tr><td>"+parseInt(percent*100)+" %</td></tr></table>";
document.getElementById("progress_fg").style.clip='rect(0,'+parseInt(percent*100)+'%,100%,0)';
document.getElementById("progress_bt").style.clip='rect(0,'+parseInt(percent*100)+'%,100%,0)';
document.getElementById("progress_ft").style.clip='rect(0,100%,100%,'+parseInt(percent*100)+'%)';
document.getElementById("progress_bt").innerHTML=font_bt;
document.getElementById("progress_ft").innerHTML=font_ft;
}
this.setModel=function(model){
percent = model;
update();
}
}
</script>
<OBJECT id="FDown" CLASSID="CLSID:96561482-93D7-4C2F-BB4A-11CED3C9915D" CODEBASE="FDownload.CAB#version=1,0,0,40" style="display:none;"></OBJECT>
<br />
<fieldset>
<legend>采集设置</legend>
<table width="100%" style="border: none;">
<tr width="100%">
<td width="15%" align="right">专辑地址:</td>
<td width="85%"><input type="text" name="SpecialURL" value="http://www.520music.com/MusicList/520music.com_5887.htm" style="width:360px;"></td>
</tr>
<tr width="100%">
<td width="15%" align="right">保存路径:</td>
<td width="85%"><input type="text" name="SavePath" value="d:\Spacial" style="width:200px;"></td>
</tr>
<tr width="100%">
<td width="15%" align="right">专辑名称:</td>
<td width="85%"><input type="text" name="SpecialName" value="" style="width:200px;"></td>
</tr>
<tr width="100%">
<td width="15%" align="right">歌手名称:</td>
<td width="85%"><input type="text" name="SinGer" value="" style="width:200px;"></td>
</tr>
<tr width="100%">
<td width="15%" align="right">唱片公司:</td>
<td width="85%"><input type="text" name="GongSi" value="" style="width:200px;"></td>
</tr>
<tr width="100%">
<td width="15%" align="right">专辑语种:</td>
<td width="85%"><input type="text" name="YuYan" value="" style="width:200px;"></td>
</tr>
<tr width="100%">
<td width="15%" align="right">发行时间:</td>
<td width="85%"><input type="text" name="Times" value="" style="width:200px;"></td>
</tr>
<tr width="100%">
<td width="15%" align="right">专辑图片:</td>
<td width="85%"><input type="text" name="PIC" value="" style="width:360px;"></td>
</tr>
<tr width="100%">
<td width="15%" align="right">专辑介绍:</td>
<td width="85%"><textarea rows="7" cols="10" name="remark" style="width: 100%; height: 120px; word-break: break-all" tabindex="2"></textarea></td>
</tr>
</table>
</fieldset>
<br />
<fieldset>
<legend>Flash DownLoad 1.2.0</legend>
<table width="100%" style="border: none;">
<tr width="100%">
<td width="15%" align="right">下载文件:</td>
<td width="85%"><span id="DownForm"></span></td>
</tr>
<tr width="100%">
<td width="15%" align="right">保存路径:</td>
<td width="85%"><span id="DownTo"></span></td>
</tr>
<tr width="100%">
<td width="15%" align="right">下载进度:</td>
<td width="85%"><span id="DownLoading"></span></td>
</tr>
<tr width="100%">
<td width="15%" align="right">下载速度:</td>
<td width="85%"><span id="DownSpeed"></span></td>
</tr>
<tr width="100%">
<td width="15%" align="right">下载状态:</td>
<td width="85%"><span id="DownState"></span></td>
</tr>
<tr width="100%">
<td width="15%" align="right">进度条:</td>
<td width="85%"><span id="ProBar" width="100%"><script>ww = ((document.body.offsetWidth/100)*85);var pb = new ProgressBar(ww,18,"navy","#FFFFFF","#8e8e8e");</script></span></td>
</tr>
</table>
</fieldset>
<br />

<Script Language="VBScript">
Dim IStr,StrSave,StrCookie
Dim CAIType
Dim MusicBody,MusicNameArr,MusicURLArr,MusicCount,MusicPtr,MusicName,MusicPlayer,MusicURL,MusicSave
Set IStr = CreateObject("IVVN.String")
'msgbox IStr.Version
FDown.BackColor = "#FFFFFF"
FDown.FillColor = "#FFFFFF"
FDown.FrameColor = "#E0E0E0"
'=============================================================================================================================================================
'FDown事件模块 开始
'=============================================================================================================================================================
'下载库通过该函数通知下载状态
Private Sub FDown_Status(ByVal lIndex, ByVal lStatus, ByVal bstrStatusParam)
On Error Resume Next
If blnDStop = True Then
FDown.bStop
Exit Sub
End If
document.getElementById("DownForm").innerText = FDown.Url
If FDown.DownLoadType = dtToFile And FDown.SavePath <> "" And FDown.Filename <> "" Then
document.getElementById("DownTo").innerText = FDown.SavePath & "\" & FDown.Filename
Else
document.getElementById("DownTo").innerText = "抓取数据..."
End If
Dim strMsg
strMsg = "线程" & lIndex + 1 & ":"
If lStatus = 0 Then
strMsg = strMsg & "解析域名 "
ElseIf lStatus = 1 Then
strMsg = strMsg & "获得IP地址 "
ElseIf lStatus = 2 Then
strMsg = strMsg & "连接服务器 "
ElseIf lStatus = 3 Then
strMsg = strMsg & "连接服务器成功 "
ElseIf lStatus = 4 Then
strMsg = strMsg & "重定向到 "
ElseIf lStatus = 5 Then
strMsg = strMsg & "开始接收数据 "
ElseIf lStatus = 6 Then
strMsg = strMsg & "下载结束 "
End If
strMsg = strMsg & bstrStatusParam & vbCrLf
document.getElementById("DownState").innerText = strMsg
End Sub
'下载库通过该事件通知文件下载进度
Private Sub FDown_Progress(ByVal dbFileSize, ByVal dbFinished, ByVal dbSpeed)
On Error Resume Next
If blnDStop = True Then
FDown.bStop
Exit Sub
End If
Dim BFile
Dim BRead
Dim BShare
Dim BSpeed
BFile = dbFileSize
BRead = dbFinished
BShare = dbFinished / (dbFileSize / 100)
BSpeed = dbSpeed
If IsNumeric(dbFinished) = True And IsNumeric(dbFileSize) = True Then
BFile = dbFileSize
BRead = dbFinished
BShare = dbFinished / (dbFileSize / 100)
pb.setModel(BRead/BFile)
document.getElementById("DownLoading").innerText = BRead & " of " & BFile & " transferred (" & Round(BShare, 2) & "%)"
End If
If IsNumeric(dbSpeed) = True Then
BSpeed = dbSpeed
document.getElementById("DownSpeed").innerText = "Throughput " & BSpeed & " /s"
End If
End Sub
'下载库通过该事件通知下载过程结束
Private Sub FDown_DownloadEnd(ByVal bSuccess)
On Error Resume Next
Select Case CAIType
Case "C1"
StrBody = FDown.Body
oSpecialName = IStr.RegContent(StrBody,"专辑名称:","</li>")
document.getElementById("SpecialName").value = oSpecialName
oSinGer = IStr.RegContent(StrBody,"歌手名称:","</li>")
document.getElementById("SinGer").value = oSinGer
oGongSi = IStr.RegContent(StrBody,"唱片公司:","</li>")
document.getElementById("GongSi").value = oGongSi
oYuYan = IStr.RegContent(StrBody,"专辑语种:","</li>")
document.getElementById("YuYan").value = oYuYan
oTimes = IStr.RegContent(StrBody,"发行时间:","</li>")
document.getElementById("Times").value = oTimes
oPIC = IStr.RegContent(StrBody,"<div class=""rightcolumn""><div id=""albuminfo""><img src=""",""">")
document.getElementById("PIC").value = oPIC
oremark = IStr.RegContent(StrBody,"<h2>专辑介绍</h2><p>","</p>")
document.getElementById("remark").value = oremark
StrSave = document.getElementById("SavePath").value & "\" & oSinGer & "\" & oSpecialName
CAIType = "C2"
Download_File 0, oPIC, StrSave & "/upload/tech/20091012/20091012012134_fe8c15fed5f808006ce95eddb7366e35.jpg", True, document.getElementById("SpecialURL").value, StrCookie
MusicBody = IStr.RegContent(StrBody,"<form name=form2 target=myplay action=../rd18playlist.htm>","<input name=""chkall2"" onclick=CheckAll(this.form) type=""button"" value=""全 选"" />")
MusicNameArr = IStr.RegContent(MusicBody,"<a href=""../mydown.htm?musicname=",""" target=_blank>",0,True)
MusicNameArr = Split(MusicNameArr,"§")
MusicURLArr = IStr.RegContent(MusicBody,"<input name=""checked"" type=""checkbox"" value=""",""" />",0,True)
MusicURLArr = Split(MusicURLArr,"§")
MusicCount = UBound(MusicURLArr)
CAIType = "C3"
MusicPtr = 0
GetMusic
Case "C3"
StrBody = FDown.Body
MusicURL = "http://wma7.520music.com/20060312/" & IStr.RegContent(StrBody,"document.write(""<PARAM NAME=\""URL\"" VALUE='""+url+""/","'>"")")
MusicSave = StrSave & "\" & MusicPtr+1 & IStr.GetFileExt(MusicURL)
CAIType = ""
StrCookie = Download_Text(0,"http://hi.520music.com/hi.htm", "gb2312", True, MusicPlayer, "")
StrCookie = FDown.Body
StrCookie = IStr.RegContent(StrCookie,"document.cookie=""","; domain=hi.520music.com;")
'MsgBox StrCookie
CAIType = "C4"
Download_File 0, MusicURL, MusicSave, False, document.getElementById("SpecialURL").value, StrCookie
Case "C4"
CAIType = "C3"
MusicPtr = MusicPtr + 1
GetMusic
End Select
If blnDStop = True Then
FDown.bStop
Exit Sub
End If
End Sub

'下载库通过该函数通知下载过程中发生的错误
Private Sub FDown_Error(ByVal lIndex, ByVal lErrorCode)
On Error Resume Next
If blnDStop = True Then
FDown.bStop
End If
document.getElementById("DownState").innerText = lErrorCode
End Sub
'=============================================================================================================================================================
'FDown事件模块 结束
'=============================================================================================================================================================
' ============================================
' 根据路径获取扩展名
' ============================================
Public Function GetFileExt(ByVal FullPath)
On Error Resume Next
Dim pos, pvs
pos = InStrRev(FullPath, ".")
pvs = InStrRev(FullPath, "?") - pos
If pvs < pos Then pvs = InStrRev(FullPath, "?")
If pos > 0 Then
If pvs > 0 Then
GetFileExt = Mid(FullPath, pos, pvs)
Else
GetFileExt = Mid(FullPath, pos)
End If
End If
End Function
'=============================================================================================================================================================
'功能函数模块 开始
'=============================================================================================================================================================
'下载远程URL数据
Function Download_Text(ByVal MetHod, ByVal Url, ByVal Charset, ByVal Async, ByVal Referer, ByVal Cookie)
On Error Resume Next
If Referer = "" Then Referer = Url
FDown.Init
FDown.DownLoadType = 1
FDown.MetHod = MetHod
FDown.Url = Url
FDown.Charset = Charset
FDown.SyncMode = Async
FDown.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1)"
FDown.URLReferer = Referer
FDown.Cookie = Cookie
FDown.FailRetryTimes = 3
FDown.DownLoad
End Function
'下载远程URL文件到本地
Function Download_File(ByVal MetHod, ByVal Url, ByVal SaveFile, ByVal Async, ByVal Referer, ByVal Cookie)
'On Error Resume Next
Dim UserAgent
Dim SavePath
Dim Filename
If Referer = "" Then Referer = Url
SavePath = Mid(SaveFile, 1, InStrRev(SaveFile, "\") - 1)
Filename = Mid(SaveFile, InStrRev(SaveFile, "\") + 1, Len(SaveFile))
Select Case LCase(GetFileExt(Url))
Case ".mp3", ".wma", ".wmv", ".wav", ".avi", ".mpeg", ".mpg", ".mid"
UserAgent = "NSPlayer/10.0.0.3708 WMFSDK/10.0"
Case ".rm", ".rmvb"
UserAgent = "RMA/1.0 (compatible; RealMedia) "
Case Else
UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1)"
End Select
'If FDown.CreateFolders(SavePath & "\" & Filename) = False Then
'Download_File = False
'Exit Function
'End If
FDown.Init
FDown.DownLoadType = 0
FDown.MetHod = MetHod
FDown.Url = Url
FDown.SavePath = SavePath
FDown.Filename = Filename
FDown.SyncMode = Async
FDown.UserAgent = UserAgent
FDown.URLReferer = Referer
FDown.Cookie = Cookie
FDown.FailRetryTimes = 3
Download_File = FDown.DownLoad
End Function
'下载远程URL头部信息
Function Download_Head(ByVal MetHod, ByVal Url, ByVal Async, ByVal Referer, ByVal Cookie, ByVal SAsync)
On Error Resume Next
Dim UserAgent
If Referer = "" Then Referer = Url
DownForm.Caption = Url
Select Case LCase(GetFileExt(Url))
Case ".mp3", ".wma", ".wmv", ".wav", ".avi", ".mpeg", ".mpg", ".mid"
UserAgent = "NSPlayer/9.0.0.2991 WMFSDK/9.0 "
Case ".rm", ".rmvb"
UserAgent = "RMA/1.0 (compatible; RealMedia) "
Case Else
UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1)"
End Select
FDown.Init
FDown.DownLoadType = 1
FDown.MetHod = MetHod
FDown.Url = Url
FDown.SyncMode = Async
FDown.UserAgent = UserAgent
FDown.URLReferer = Referer
FDown.Cookie = Cookie
FDown.FailRetryTimes = 3
Download_Head = FDown.DownLoadHead(Async, SAsync)
End Function
'下载Cookie
Function Download_Cookie(ByVal MetHod, ByVal Url, ByVal Referer, ByVal UserAgent, ByVal Cookie, ByVal N)
On Error Resume Next
If Referer = "" Then Referer = Url
FDown.Init
FDown.DownLoadType = 0
FDown.MetHod = MetHod
Download_Cookie = FDown.DownloadCookie(Url,Referer,UserAgent,Cookie,N)
End Function
'开始采集
Sub StartCai()
CAIType = "C1"
Download_Text 0, document.getElementById("SpecialURL").value, "gb2312", False, "", ""
End Sub
'下载音乐
Sub GetMusic()
If MusicPtr>MusicCount Then
MsgBox "全部下载完成!"
Exit Sub
End If
MusicPlayer = "http://www.520music.com/play/" & MusicURLArr(MusicPtr) & ".htm"
Download_Text 0, MusicPlayer, "gb2312", False, "", ""
End Sub
</Script>
<br />
<input type='button' value=' 开始采集 ' onclick='StartCai()'>
</BODY>
</HTML>