一个Asp团购API读取函数
[ 2011-11-01 14:35:21 | 作者: admin ]
出自:http://dev.tot.name/asp/html/20101123/20101123133239.htm
以下是团购XML文件的数据:
以下是ASP读取团购API的函数:
然后在程序中如下引用:
<%=GetTgXml("http://团购API网址")%>
以下是团购XML文件的数据:
<?xml version="1.0" encoding="utf-8" ?>
- <urlset>
- <url>
<loc>http://www.totcms.com/team.php?id=9</loc>
- <data>
- <display>
<website>totcms</website>
<siteurl>http://www.totcms.com</siteurl>
<city>全国</city>
<title>卖疯啦!超推荐之Dior史上最佳睫毛膏!36元抢购迪奥BlackOut后台炫黑睫毛膏!内含古埃及艳后专用睫毛碳粉,超黑妆效,极致惊艳埃及艳后的惊艳妆效你真的可以轻松拥有</title>
<image>http://www.totcms.com/static/team/2010/1118/12900802148912.jpg</image>
<startTime>1290441600</startTime>
<endTime>1290528000</endTime>
<value>360.00</value>
<price>36.00</price>
<rebate>1</rebate>
<bought>355</bought>
</display>
</data>
</url>
</urlset>
- <urlset>
- <url>
<loc>http://www.totcms.com/team.php?id=9</loc>
- <data>
- <display>
<website>totcms</website>
<siteurl>http://www.totcms.com</siteurl>
<city>全国</city>
<title>卖疯啦!超推荐之Dior史上最佳睫毛膏!36元抢购迪奥BlackOut后台炫黑睫毛膏!内含古埃及艳后专用睫毛碳粉,超黑妆效,极致惊艳埃及艳后的惊艳妆效你真的可以轻松拥有</title>
<image>http://www.totcms.com/static/team/2010/1118/12900802148912.jpg</image>
<startTime>1290441600</startTime>
<endTime>1290528000</endTime>
<value>360.00</value>
<price>36.00</price>
<rebate>1</rebate>
<bought>355</bought>
</display>
</data>
</url>
</urlset>
以下是ASP读取团购API的函数:
function GetTgXml(tgapiurl)
on error resume next
dim xmlhttp,xmlDom,t_sitetitle,t_title,t_url,t_img,t_start,t_end,t_priceold,t_pricenow,t_joined,t_days,gethtmls
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET",tgapiurl, false
xmlhttp.Send
Set xmlDom = server.createObject("microsoft.xmldom")
xmlDom.async=False
xmlDom.ValidateOnParse=false
xmlDom.load(xmlhttp.responseXML)
if xmlDom.ReadyState>2 Then
Set list=xmlDom.getElementsByTagName("url")
if(list.Length>0) then
t_sitetitle=list.Item(list.Length-1).selectSingleNode("data/display/website").text
t_title=list.Item(list.Length-1).selectSingleNode("data/display/title").text
t_url=list.Item(list.Length-1).selectSingleNode("loc").text
t_url="go.asp?u="&server.URLEncode(t_url)
t_img=list.Item(list.Length-1).selectSingleNode("data/display/image").text
t_start=list.Item(list.Length-1).selectSingleNode("data/display/startTime").text
t_end=list.Item(list.Length-1).selectSingleNode("data/display/endTime").text
t_priceold=list.Item(list.Length-1).selectSingleNode("data/display/value").text
t_pricenow=list.Item(list.Length-1).selectSingleNode("data/display/price").text
t_joined=list.Item(list.Length-1).selectSingleNode("data/display/bought").text
gethtmls=gethtmls&"<li><div class=""tgimg""><a href="""&t_url&""" target=""_blank""><img src="""&t_img&""" alt="""&t_title&""" width=""336"" height=""212"" border=""0"" /></a></div>"
gethtmls=gethtmls&"<div class=""tgtitle""><h2>["&t_sitetitle&"]<a href="""&t_url&""" target=""_blank"" title="""&t_title&""">"&t_title&"</a></h2></div>"
gethtmls=gethtmls&"<div class=""tgprice"">原价:<span class=""oldprice"">"&t_priceold&"</span> 现价:<span class=""nowprice"">"&t_pricenow&"</span> 参加人数:"&t_joined&"</div><div class=""days"">剩余时间:<label class=""exptime_tip"" style=""display:none"">"&t_end&"</label><label> </label></div></li>"
end if
end if
set xmlDom=nothing
set xmlhttp=nothing
GetTgXml=gethtmls
end function
on error resume next
dim xmlhttp,xmlDom,t_sitetitle,t_title,t_url,t_img,t_start,t_end,t_priceold,t_pricenow,t_joined,t_days,gethtmls
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET",tgapiurl, false
xmlhttp.Send
Set xmlDom = server.createObject("microsoft.xmldom")
xmlDom.async=False
xmlDom.ValidateOnParse=false
xmlDom.load(xmlhttp.responseXML)
if xmlDom.ReadyState>2 Then
Set list=xmlDom.getElementsByTagName("url")
if(list.Length>0) then
t_sitetitle=list.Item(list.Length-1).selectSingleNode("data/display/website").text
t_title=list.Item(list.Length-1).selectSingleNode("data/display/title").text
t_url=list.Item(list.Length-1).selectSingleNode("loc").text
t_url="go.asp?u="&server.URLEncode(t_url)
t_img=list.Item(list.Length-1).selectSingleNode("data/display/image").text
t_start=list.Item(list.Length-1).selectSingleNode("data/display/startTime").text
t_end=list.Item(list.Length-1).selectSingleNode("data/display/endTime").text
t_priceold=list.Item(list.Length-1).selectSingleNode("data/display/value").text
t_pricenow=list.Item(list.Length-1).selectSingleNode("data/display/price").text
t_joined=list.Item(list.Length-1).selectSingleNode("data/display/bought").text
gethtmls=gethtmls&"<li><div class=""tgimg""><a href="""&t_url&""" target=""_blank""><img src="""&t_img&""" alt="""&t_title&""" width=""336"" height=""212"" border=""0"" /></a></div>"
gethtmls=gethtmls&"<div class=""tgtitle""><h2>["&t_sitetitle&"]<a href="""&t_url&""" target=""_blank"" title="""&t_title&""">"&t_title&"</a></h2></div>"
gethtmls=gethtmls&"<div class=""tgprice"">原价:<span class=""oldprice"">"&t_priceold&"</span> 现价:<span class=""nowprice"">"&t_pricenow&"</span> 参加人数:"&t_joined&"</div><div class=""days"">剩余时间:<label class=""exptime_tip"" style=""display:none"">"&t_end&"</label><label> </label></div></li>"
end if
end if
set xmlDom=nothing
set xmlhttp=nothing
GetTgXml=gethtmls
end function
然后在程序中如下引用:
<%=GetTgXml("http://团购API网址")%>
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1736
这篇日志没有评论。
此日志不可发表评论。