欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP读取XML实例 优酷专辑采集程序 雷锋版

程序员文章站 2022-06-17 14:06:34
复制代码 代码如下: 雷锋|优酷-专辑 采集程序

复制代码 代码如下:

<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="http://www.youku.com/playlist/" target="_blank">点我查找优酷专辑</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">例如专辑:http://www.youku.com/playlist_show/id_2344971.html</td></tr>
<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="http://www.youku.com/playlist/rss/id/4014024"&v_urlb
response.write "<div align=""center""><a href="&v_url&" target=_blank >当前专辑的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="http://search.yahoo.com/mrss" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<title>优酷-专辑-乾隆与香妃(27集)的视频</title>
<description>优酷专辑乾隆与香妃(27集)的视频</description>
<link>http://www.youku.com/playlist/</link>
<lastbuilddate>wed, 16 dec 2009 13:34:06 +0800</lastbuilddate>
<generator>novajax feed writer</generator>
<image>
<url>http://www.youku.com/index/img/youkulogo.gif</url>
<title>优酷网-中国第一视频网,提供视频播放,视频发布,视频搜索</title>
<link>http://www.youku.com</link>
<description>视频服务平台,提供视频播放,视频发布,视频搜索、视频分享</description>
</image>
<item>
<title>乾隆与香妃01</title>
<link>http://www.youku.com/v_show/id_xmtm4nty5ndk2_rss.html</link>
<description><![cdata[<a href="http://www.youku.com/v_show/id_xmtm4nty5ndk2_rss.html"><img src="http://g3.ykimg.com/0100641f464b178ea61f9f011876cad9220d5d-8dae-b491-fd1b-138f2dc75b23" border="0" width="120" height="90" vspace="4" hspace="4" title="乾隆与香妃01" target="_blank" /></a> <a href="http://www.youku.com/v_show/id_xmtm4nty5ndk2_rss.html"><img src="http://g1.ykimg.com/" border="0" width="120" height="90" vspace="4" hspace="4" title="乾隆与香妃01" target="_blank" /></a> <a href="http://www.youku.com/v_show/id_xmtm4nty5ndk2_rss.html"><img src="http://g1.ykimg.com/" border="0" width="120" height="90" vspace="4" hspace="4" title="乾隆与香妃01" target="_blank" /></a> <p></p>]]></description>
<itunes:duration>43:42</itunes:duration>
<itunes:keywords>尊龙,努尔比亚,恬妞,翁虹,阿依努尔,古海尔,谭非翎,瓦力伊,斯拉木江斯</itunes:keywords>
<author>為傑沉淪</author>
<comments>http://www.youku.com/v_show/id_xmtm4nty5ndk2_rss.html#comments</comments>
<pubdate>wed, 16 dec 2009 13:34:06 +0800</pubdate>
<guid>34642374</guid>
<enclosure type="application/x-shockwave-flash" url="http://player.youku.com/player.php/sid/34642374/v.swf"></enclosure>
</item>
<item>
<title>乾隆与香妃02</title>
<link>http://www.youku.com/v_show/id_xmtm4nty5nti4_rss.html</link>
<description><![cdata[<a href="http://www.youku.com/v_show/id_xmtm4nty5nti4_rss.html"><img src="http://g2.ykimg.com/0100641f464b178d99ef1f011876ca86f7b34b-b71c-2f1e-36b5-d0804f32ab42" border="0" width="120" height="90" vspace="4" hspace="4" title="乾隆与香妃02" target="_blank" /></a> <a href="http://www.youku.com/v_show/id_xmtm4nty5nti4_rss.html"><img src="http://g1.ykimg.com/" border="0" width="120" height="90" vspace="4" hspace="4" title="乾隆与香妃02" target="_blank" /></a> <a href="http://www.youku.com/v_show/id_xmtm4nty5nti4_rss.html"><img src="http://g1.ykimg.com/" border="0" width="120" height="90" vspace="4" hspace="4" title="乾隆与香妃02" target="_blank" /></a> <p></p>]]></description>
<itunes:duration>41:26</itunes:duration>
<itunes:keywords>尊龙,努尔比亚,恬妞,翁虹,阿依努尔,古海尔,谭非翎,瓦力伊,斯拉木江斯</itunes:keywords>
<author>為傑沉淪</author>
<comments>http://www.youku.com/v_show/id_xmtm4nty5nti4_rss.html#comments</comments>
<pubdate>wed, 16 dec 2009 13:34:06 +0800</pubdate>
<guid>34642382</guid>
<enclosure type="application/x-shockwave-flash" url="http://player.youku.com/player.php/sid/34642382/v.swf"></enclosure>
</item>
</channel>
</rss>