<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
dim MusicName,singer
MusicName=request("MusicName")
singer=request("singer")
%><%
on error resume next
Const adTypeBinary = 1
Const adTypeText = 2
Function Bytes2bStr(vin)
Dim BytesStream,StringReturn
Set BytesStream = Server.CreateObject("ADODB.Stream")
With BytesStream
.Type = adTypeText
.Open
.WriteText vin
.Position = 0
.Charset = "GB2312"
.Position = 2
StringReturn = .ReadText
.close
End With
Set BytesStream = Nothing
Bytes2bStr = StringReturn
End Function
Key = MusicName&"%20%20"&Singer
Url ="http://mp3.baidu.com/m?f=ms&rn=10&tn=baidump3lyric&ct=150994944&word="&Key&"&lm=-1"
set oSend=createobject("Microsoft.XMLHTTP")
SourceCode = oSend.open ("GET",url,false)
oSend.send()
SourceCode = bytes2BSTR(oSend.responseBody)
if instr(SourceCode,"</div><div class="&chr(34)&"BlueBG"&chr(34)&"><strong>") > 0 then
betw=instr(SourceCode,"</div><div class="&chr(34)&"BlueBG"&chr(34)&"><strong>")-instr(SourceCode,"<div style="&chr(34)&"padding-left:10px;line-height:20px;padding-top:1px"&chr(34)&">")
else
betw=instr(SourceCode,"<div class="&chr(34)&"pg"&chr(34)&"></div>")-instr(SourceCode,"<div style="&chr(34)&"padding-left:10px;line-height:20px;padding-top:1px"&chr(34)&">")
end if
first=instr(SourceCode,"<div style="&chr(34)&"padding-left:10px;line-height:20px;padding-top:1px"&chr(34)&">")
SourceCode = Mid(SourceCode,first,abs(betw))
if err.number<>0 then
Response.Write("<center><br><a href='http://mp3.baidu.com/m?f=ms&tn=baidump3lyric&ct=150994944&lf=2&rn=10&word="&MusicName&"&lm=-1' target='_blank'>点此强力搜索《"&Singer&" "&MusicName&"》歌词!</a><br></center>")
else
SourceCode=replace(SourceCode,"<div style="&chr(34)&"padding-left:10px;line-height:20px;padding-top:1px"&chr(34)&">","")
SourceCode=replace(SourceCode,"<font style=color:#e10900>","<FONT COLOR=#FF6600>")
SourceCode=replace(SourceCode,"</div>","")
SourceCode=replace(SourceCode,""&chr(13)&chr(10)&""&chr(13)&chr(10)&""&chr(13)&chr(10)&"","")
SourceCode=replace(SourceCode,"<br><br><br>","")
SourceCode=replace(SourceCode,"<br>",""&chr(13)&chr(10)&"<br>")
Response.Write(SourceCode)
end if
%>
无格式 请大家自行加如页面效果 SourceCode 为歌词部分
详细操作
Url ="http://mp3.baidu.com/m?f=ms&rn=10&tn=baidump3lyric&ct=150994944&word="&Key&"&lm=-1"
key=歌曲名字 歌手名字
Key = MusicName&"%20%20"&Singer
key = 调用数据歌曲名字 调用歌手名字
SourceCode = bytes2BSTR(oSend.responseBody)
if instr(SourceCode,"</div><div class="&chr(34)&"BlueBG"&chr(34)&"><strong>") > 0 then
betw=instr(SourceCode,"</div><div class="&chr(34)&"BlueBG"&chr(34)&"><strong>")-instr(SourceCode,"<div style="&chr(34)&"padding-left:10px;line-height:20px;padding-top:1px"&chr(34)&">")
else
betw=instr(SourceCode,"<div class="&chr(34)&"pg"&chr(34)&"></div>")-instr(SourceCode,"<div style="&chr(34)&"padding-left:10px;line-height:20px;padding-top:1px"&chr(34)&">")
end if
first=instr(SourceCode,"<div style="&chr(34)&"padding-left:10px;line-height:20px;padding-top:1px"&chr(34)&">")
SourceCode = Mid(SourceCode,first,abs(betw))
if err.number<>0 then
SOURCECODE= http://mp3.baidu.com/m?f=ms&rn=10&tn=baidump3lyric&ct=150994944&word="&Key&"&lm=-1" 页面中
从百度的<div style="padding-left:10px;line-height:20px;padding-top:1px">开始
结尾 <div class="pg"></div> 这里表示歌曲只有个歌词
如果搜索出多个歌词 就从 <div style="padding-left:10px;line-height:20px;padding-top:1px">开始
结尾 </div><div class="BlueBG"><strong>
然后开始做替换 将 抓取到的内容进行替换
SourceCode=replace(SourceCode,"<div style="&chr(34)&"padding-left:10px;line-height:20px;padding-top:1px"&chr(34)&">","")
SourceCode=replace(SourceCode,"<font style=color:#e10900>","<FONT COLOR=#FF6600>")
SourceCode=replace(SourceCode,"</div>","")
SourceCode=replace(SourceCode,""&chr(13)&chr(10)&""&chr(13)&chr(10)&""&chr(13)&chr(10)&"","")
SourceCode=replace(SourceCode,"<br><br><br>","")
SourceCode=replace(SourceCode,"<br>",""&chr(13)&chr(10)&"<br>")
将 抓区出来的 <div style="&chr(34)&"padding-left:10px;line-height:20px;padding-top:1px"&chr(34)&">替换为无
将 抓区出来的 <font style=color:#e10900>替换为<FONT COLOR=#FF6600>
另外说一下为什么是广告 是因为你添加的搜索的关键词 在baidu无纪录 所以就是
SourceCode = Mid(SourceCode,first,abs(betw))
if err.number<>0 then
没有歌词就sourcecode =
<center><br><a href='http://mp3.baidu.com/m?f=ms&tn=baidump3lyric&ct=150994944&lf=2&rn=10&word="&MusicName&"&lm=-1' target='_blank'>点此强力搜索《"&Singer&" "&MusicName&"》歌词!</a><br></center>
上面的代码粘贴进一个文档里
上面的代码粘贴进一个文档里
修改为asp文件
然后上传服务器
测试一下
http://xxxxx.com/你修改的文件名字.asp?singer=歌手&musicname=歌曲名字
id等于 歌曲ID
测试成功后
将播放器页面加入
<iframe align="center" width="高度" height="宽度" src="文件名地址?id=歌曲ID号" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
本文来自: 牛站长论坛(http://www.nb5.cn/) 详细文章参考:http://www.nb5.cn/thread-26537-1-1.html
|