用XMLHTTP很好的一个例子
程序员文章站
2022-04-14 18:53:41
进入www.ting88.com的网站,把歌手专辑页面的url复制到文本框中再提交就可以得到歌曲的下载路径,如:http://www.ting88.com/musiclis...
进入www.ting88.com的网站,把歌手专辑页面的url复制到文本框中再提交就可以得到歌曲的下载路径,如:http://www.ting88.com/musiclist/4141.htm
源程序如下:
<%
on error resume next
dim id,url,getcode,m,i,j,s,d,ns,nd,num,name
id=trim(request.querystring("id"))
'1.获取原网页所有内容
function gethttppage(url)
dim http
set http=server.createobject("microsoft.xmlhttp")
http.open "get",url,false
http.send()
if http.readystate<>4 then
exit function
end if
gethttppage=bytestobstr(http.responsebody,"gb2312")
set http=nothing
if err.number<>0 then err.clear
end function
'2.编码转换
function bytestobstr(body,cset)
dim objstream
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.mode =3
objstream.open
objstream.write body
objstream.position = 0
objstream.type = 2
objstream.charset = cset
bytestobstr = objstream.readtext
objstream.close
set objstream = nothing
end function
'得到明码url
function myreplace(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
end function
if id="1" then
url=trim(request.form("txturl"))
if url="" then
response.redirect("getmusic.asp")
response.end()
end if
'url="http://www.ting88.com/musiclist/1454.htm"
s=0
d=0
ns=0
nd=0
getcode=gethttppage(url)
num=mid(getcode,instrrev(getcode,".<a href")-3,2) '获取歌曲的数目
name=mid(getcode,instr(getcode,"歌手姓名:")+5,10) '获取歌手
m="http://218.75.78.189/33445566/"
response.write "<center>该面页共找到 " & name & "的 <font color=red>" & num& "</font> 首歌曲" & "<br/><br/>"
response.write "<table width='80%' border='1' bordercolor='#a4c8ff' cellpadding='0' cellspacing='0'><tr><td>页面url:<a href='" & url & "' target='_blank'>" & url & "</a></td></tr></table><hr width='80%'>"
response.write "<table width='80%' border='0' cellpadding='0' cellspacing='0' bgcolor='#a4c8ff'><tr><td><table border='0' width='100%' cellpadding='2' cellspacing='1'><tr><td align=center bgcolor='#ffffff'>序号</td><td align=center bgcolor='#ffffff'>歌名</td><td align=center bgcolor='#ffffff'>操作</td></tr>"
for i=1 to num
s=instr(i+s,getcode,"checked"" value='")
d=instr(i+d,getcode,"kwd'>")
ns=instr(i+ns,getcode,"word=")
nd=instr(i+nd,getcode,"&inc=")
response.write " <tr><td align=center bgcolor='#ffffff'>" & i & "</td><td bgcolor='#ffffff'> <a href='" & m & myreplace(mid(getcode,s+16,d-s-13)) & "'>" & mid(getcode,ns+5,nd-ns-5) & "</a><br/></td><td align=center bgcolor='#ffffff'><a href='" & m & myreplace(mid(getcode,s+16,d-s-13)) & "'>下载</a></td></tr>"
next
response.write "</table></td></tr></table></center>"
end if
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>获取专辑歌曲的url地址</title>
</head>
<body>
<form name="form1" method="post" action="getmusic.asp?id=1">
<table width='80%' border='0' align="center" cellpadding='0' cellspacing='0' bgcolor='#a4c8ff'>
<tr><td><table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
<tr>
<td height="30">获取专辑歌曲的url地址</td>
</tr>
<tr>
<td height="30" bgcolor="#ffffff">网页地址:
<input name="txturl" type="text" id="txturl" size="80" maxlength="100"></td>
</tr>
<tr>
<td height="30" bgcolor="#ffffff"> <input type="submit" name="submit" value="提 交" style="width:60">
<input name="reset" type="reset" id="reset" value="重 置" style="width:60"></td>
</tr>
</table></td></tr></table>
</form>
</body>
</html>
源程序如下:
<%
on error resume next
dim id,url,getcode,m,i,j,s,d,ns,nd,num,name
id=trim(request.querystring("id"))
'1.获取原网页所有内容
function gethttppage(url)
dim http
set http=server.createobject("microsoft.xmlhttp")
http.open "get",url,false
http.send()
if http.readystate<>4 then
exit function
end if
gethttppage=bytestobstr(http.responsebody,"gb2312")
set http=nothing
if err.number<>0 then err.clear
end function
'2.编码转换
function bytestobstr(body,cset)
dim objstream
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.mode =3
objstream.open
objstream.write body
objstream.position = 0
objstream.type = 2
objstream.charset = cset
bytestobstr = objstream.readtext
objstream.close
set objstream = nothing
end function
'得到明码url
function myreplace(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
end function
if id="1" then
url=trim(request.form("txturl"))
if url="" then
response.redirect("getmusic.asp")
response.end()
end if
'url="http://www.ting88.com/musiclist/1454.htm"
s=0
d=0
ns=0
nd=0
getcode=gethttppage(url)
num=mid(getcode,instrrev(getcode,".<a href")-3,2) '获取歌曲的数目
name=mid(getcode,instr(getcode,"歌手姓名:")+5,10) '获取歌手
m="http://218.75.78.189/33445566/"
response.write "<center>该面页共找到 " & name & "的 <font color=red>" & num& "</font> 首歌曲" & "<br/><br/>"
response.write "<table width='80%' border='1' bordercolor='#a4c8ff' cellpadding='0' cellspacing='0'><tr><td>页面url:<a href='" & url & "' target='_blank'>" & url & "</a></td></tr></table><hr width='80%'>"
response.write "<table width='80%' border='0' cellpadding='0' cellspacing='0' bgcolor='#a4c8ff'><tr><td><table border='0' width='100%' cellpadding='2' cellspacing='1'><tr><td align=center bgcolor='#ffffff'>序号</td><td align=center bgcolor='#ffffff'>歌名</td><td align=center bgcolor='#ffffff'>操作</td></tr>"
for i=1 to num
s=instr(i+s,getcode,"checked"" value='")
d=instr(i+d,getcode,"kwd'>")
ns=instr(i+ns,getcode,"word=")
nd=instr(i+nd,getcode,"&inc=")
response.write " <tr><td align=center bgcolor='#ffffff'>" & i & "</td><td bgcolor='#ffffff'> <a href='" & m & myreplace(mid(getcode,s+16,d-s-13)) & "'>" & mid(getcode,ns+5,nd-ns-5) & "</a><br/></td><td align=center bgcolor='#ffffff'><a href='" & m & myreplace(mid(getcode,s+16,d-s-13)) & "'>下载</a></td></tr>"
next
response.write "</table></td></tr></table></center>"
end if
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>获取专辑歌曲的url地址</title>
</head>
<body>
<form name="form1" method="post" action="getmusic.asp?id=1">
<table width='80%' border='0' align="center" cellpadding='0' cellspacing='0' bgcolor='#a4c8ff'>
<tr><td><table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
<tr>
<td height="30">获取专辑歌曲的url地址</td>
</tr>
<tr>
<td height="30" bgcolor="#ffffff">网页地址:
<input name="txturl" type="text" id="txturl" size="80" maxlength="100"></td>
</tr>
<tr>
<td height="30" bgcolor="#ffffff"> <input type="submit" name="submit" value="提 交" style="width:60">
<input name="reset" type="reset" id="reset" value="重 置" style="width:60"></td>
</tr>
</table></td></tr></table>
</form>
</body>
</html>
上一篇: 用ASP和SQL实现基于Web的事件日历
下一篇: 实例讲解ASP实现抓取网上房产信息