用XMLHTTP很好的一个例子

2018-09-06 11:19

阅读:433

  进入的网站,把歌手专辑页面的URL复制到文本框中再提交就可以得到歌曲的下载路径,如:

源程序如下:

<%
onerrorresumenext
dimid,url,getCode,m,i,j,s,d,ns,nd,num,name
id=trim(request.querystring(id))
1.获取原网页所有内容
FunctiongetHTTPPage(url)
dimhttp
sethttp=Server.createobject(Microsoft.XMLHTTP)
Http.openGET,url,false
Http.send()
ifHttp.readystate<>4then
exitfunction
endif
getHTTPPage=bytesToBSTR(Http.responseBody,GB2312)
sethttp=nothing
iferr.number<>0thenerr.Clear
Endfunction

2.编码转换
FunctionBytesToBstr(body,Cset)
dimobjstream
setobjstream=Server.createObject(adodb.stream)
objstream.Type=1
objstream.Mode=3
objstream.Open
objstream.Writebody
objstream.Position=0
objstream.Type=2
objstream.Charset=Cset
BytesToBstr=objstream.ReadText
objstream.Close
setobjstream=nothing
EndFunction

得到明码URL
functionMyReplace(ConvStr)
ConvStr=replace(ConvStr,YVI,1)
ConvStr=replace(ConvStr,ESR,2)
ConvStr=replace(ConvStr,SXN,3)
ConvStr=replace(ConvStr,STI,4)
ConvStr=replace(ConvStr,WFU,5)
ConvStr=replace(ConvStr,LQU,6)
ConvStr=replace(ConvStr,QGI,7)
ConvStr=replace(ConvStr,BLA,8)
ConvStr=replace(ConvStr,JFU,9)
ConvStr=replace(ConvStr,LSN,0)
ConvStr=replace(ConvStr,XPG,/)
ConvStr=replace(ConvStr,XQD,.)
ConvStr=replace(ConvStr,,)
ConvStr=replace(ConvStr,%20,)
ConvStr=replace(ConvStr,KWD,Wma)
MyReplace=ConvStr
endfunction

ifid=1then
url=trim(request.form(txturl))
ifurl=then
response.redirect(GetMusic.asp)
response.end()
endif
url=
s=0
d=0
ns=0
nd=0
getCode=getHTTPPage(url)
num=mid(getCode,instrrev(getCode,.<ahref)-3,2)获取歌曲的数目
name=mid(getCode,instr(getCode,歌手姓名:)+5,10)获取歌手
m=
response.write<center>该面页共找到&name&的<fontcolor=red>&num&</font>首歌曲&<br/><br/>
response.write<tablewidth=80%border=1bordercolor=#A4C8FFcellpadding=0cellspacing=0><tr><td>页面URL:<ahref=&url&>&url&</a></td></tr></table><hrwidth=80%>
response.write<tablewidth=80%border=0cellpadding=0cellspacing=0bgcolor=#A4C8FF><tr><td><tableborder=0width=100%cellpadding=2cellspacing=1><tr><tdalign=centerbgcolor=#FFFFFF>序号</td><tdalign=centerbgcolor=#FFFFFF>歌名</td><tdalign=centerbgcolor=#FFFFFF>操作</td></tr>
fori=1tonum
s=instr(i+s,getCode,checkedvalue=)
d=instr(i+d,getCode,KWD>)
ns=instr(i+ns,getCode,word=)
nd=instr(i+nd,getCode,&inc=)
response.write<tr><tdalign=centerbgcolor=#FFFFFF>&i&</td><tdbgcolor=#FFFFFF><ahref=&m&MyReplace(mid(getCode,s+16,d-s-13))&>&mid(getCode,ns+5,nd-ns-5)&</a><br/></td><tdalign=centerbgcolor=#FFFFFF><ahref=&m&MyReplace(mid(getCode,s+16,d-s-13))&>下载</a></td></tr>
next
response.write</table></td></tr></table></center>
endif


%>
<html>
<head>
<metahttp-equiv=Content-Typecontent=text/html;charset=gb2312>
<title>获取专辑歌曲的URL地址</title>
</head>
<body>
<formname=form1method=postaction=GetMusic.asp?id=1>
<tablewidth=80%border=0align=centercellpadding=0cellspacing=0bgcolor=#A4C8FF>
<tr><td><tablewidth=100%border=0align=centercellpadding=2cellspacing=1>
<tr>
<tdheight=30>获取专辑歌曲的URL地址</td>
</tr>
<tr>
<tdheight=30bgcolor=#FFFFFF>网页地址:
<inputname=txturltype=textid=txturlsize=80maxlength=100></td>
</tr>
<tr>
<tdheight=30bgcolor=#FFFFFF><inputtype=submitname=Submitvalue=提交style=width:60>
<inputname=Resettype=resetid=Resetvalue=重置style=width:60></td>
</tr>
</table></td></tr></table>
</form>
</body>
</html>


评论


亲,登录后才可以留言!