ASP读取XML实例 优酷专辑采集程序 雷锋版
2018-09-06 13:05
复制代码 代码如下:
<title>雷锋优酷-专辑 采集程序</title></head>
<form name=form1 method=post action=?action=add>
<table width=95% border=0 align=center cellpadding=0 cellspacing=1 class=tableBorder>
<tr><th colspan=2 align=center class=tableHeaderText><<<< <font color=red>雷锋优酷-专辑 采集程序</font> >>>></td></tr>
<tr><td align=center><a href=点我查找优酷专辑</a>
</td>
</tr>
<tr><td bgcolor=#FFFFFF align=center>专辑地址:<input name=maxz type=text value=<%=Request(maxz)%> size=50></td></tr>
<tr><td align=center bgcolor=#FFFFFF>例如专辑:
<tr><td align=center bgcolor=#FFFFFF><input name=action type=submit id=action value=提交分析该专辑地址></td></tr>
<tr><td align=center bgcolor=#FFFFFF></td></tr>
</table>
</form>
<%
if Request(action)=add Then
maxz=request.Form(maxz)
v_urla=Split(maxz,/id_)(1)
v_urlb=Replace(v_urla,.html,)
v_url=
response.write <div align=center><a href=&v_url& >当前专辑的XML:&v_url&</a></div>
Function GetPageContent(Url)
Dim HTTPObj
On Error Resume Next
Set HTTPObj = Server.CreateObject(Microsoft.XMLHTTP)
With HTTPObj
.Open Get, Url, False, ,
.Send
End With
if HTTPObj.Readystate <> 4 then
Set HTTPObj = Nothing
GetPageContent = False
Exit Function
end if
GetPageContent = replace(HTTPObj.responseText,UTF-8,gb2312)
Set HTTPObj = Nothing
End Function
strXML=GetPageContent(&v_url&)
Set objXML = Server.CreateObject(Microsoft.XMLDOM)
objXML.validateonparse = true
objXML.async=false
objXML.loadXML(strXML)
set objRootElement = objXML.documentElement
if not isObject(objRootElement) then
Response.Write(no file loaded)
else
Set ChannelList=objXML.getElementsByTagName(item)
if isnull(objXML.getElementsByTagName(item) ) then
response.Write(读取失败)
response.End()
else
Set Statistics=objXML.getElementsByTagName(title)
set KeywordList=objXML.getElementsbytagname(lastBuildDate)
response.write 共有:&keywordlist.length-1&个频道
response.write <div align=center><h4>专辑名称:&Statistics.item(0).text&</h4>
v_name=REPLACE(Statistics.item(0).text,优酷-专辑-,)
zt_name=REPLACE(v_name,的视频,)
response.write <div align=center><h4>专辑名称:<font color=red>&zt_name&</font></h4>
response.write <center><form method=post action=../admin_add.asp>
response.write <input type=hidden name=db_channel value=&zt_name& /><br>
response.write <input type=hidden name=db_player value=youku />
response.write <textarea name=db_url rows=15 cols=100>
for j=0 to ChannelList.length-1
dim ibb
response.write &ChannelList.item(j).childnodes(0).text&$&ChannelList.item(j).childnodes(8).text&chr(13)&
ibb=ibb+1
next
response.write </textarea><br /><input type=submit value=修改好了提交 /></form></center>
response.write <div align=center><h4>共提取到:<font color=red>&ibb&</font>个节目核实后提交</h4></div><br>
end if
end if
%>
<%End If %>
以上程序是以优酷的专辑列表为例做的一个 asp读取xml的实例!
将以上代码保存为 XML.ASP 在IIS环境下运行就可以采集优酷专辑的数据了!
其实上面的获取的是下面的xml文件
复制代码 代码如下:
<?xml version=1.0 encoding=utf-8?>
<!-- generator=Novajax Feed Writer -->
<rss version=2.0 xmlns:media=
<channel>
<title>优酷-专辑-乾隆与香妃(27集)的视频</title>
<description>优酷专辑乾隆与香妃(27集)的视频</description>
<link>
<lastBuildDate>Wed, 16 Dec 2009 13:34:06 +0800</lastBuildDate>
<generator>Novajax Feed Writer</generator>
<image>
<url>
<title>优酷网-中国第一视频网,提供视频播放,视频发布,视频搜索</title>
<link>
<description>视频服务平台,提供视频播放,视频发布,视频搜索、视频分享</description>
</image>
<item>
<title>乾隆与香妃01</title>
<link>
<description><![CDATA[<a href=乾隆与香妃01 /></a> <a href=乾隆与香妃01 /></a> <a href=乾隆与香妃01 /></a> <p></p>]]></description>
<itunes:duration>43:42</itunes:duration>
<itunes:keywords>尊龙,努尔比亚,恬妞,翁虹,阿依努尔,古海尔,谭非翎,瓦力伊,斯拉木江斯</itunes:keywords>
<author>為傑沉淪</author>
<comments>
<pubDate>Wed, 16 Dec 2009 13:34:06 +0800</pubDate>
<guid>34642374</guid>
<enclosure type=application/x-shockwave-flash url=
</item>
<item>
<title>乾隆与香妃02</title>
<link>
<description><![CDATA[<a href=乾隆与香妃02 /></a> <a href=乾隆与香妃02 /></a> <a href=乾隆与香妃02 /></a> <p></p>]]></description>
<itunes:duration>41:26</itunes:duration>
<itunes:keywords>尊龙,努尔比亚,恬妞,翁虹,阿依努尔,古海尔,谭非翎,瓦力伊,斯拉木江斯</itunes:keywords>
<author>為傑沉淪</author>
<comments>
<pubDate>Wed, 16 Dec 2009 13:34:06 +0800</pubDate>
<guid>34642382</guid>
<enclosure type=application/x-shockwave-flash url=
</item>
</channel>
</rss>
文章标题:ASP读取XML实例 优酷专辑采集程序 雷锋版
文章链接:http://soscw.com/index.php/essay/10892.html