当前位置: 首页 > 胡说八道 > 正文

专门为google量身定做的sitemap生成代码(动态)

例子:
如你是文章网站,文章有2000条,那你修改下对应你的文章数据表,即可生成除了所有目录文件外,还生成你的动态2000条地址,绝对的没话说,生成速度非常快
把下面代码保存为sitemap.asp文件,修改我已注明的几个地方,其他的一概不要修改,好不好用过才知道


[code]
<!–#include file="conn.asp"–>
<%
session("count")=0
strURL = "http://" &amp;amp; request.servervariables("SERVER_NAME") &amp;amp; _
left(request.servervariables("SCRIPT_NAME"),len(request.servervariables("SCRIPT_NAME"))-len("/sitemap.asp"))
dim foolcat
foolcat = foolcat + "<?xml version=""1.0"" encoding=""UTF-8""?>"
foolcat = foolcat + "<!–Google Site Map File Generated by http://www.xxx.com " &amp;amp; return_RFC822_Date(now,"GMT") &amp;amp; "–>"
foolcat = foolcat + "<urlset xmlns=""http://www.google.com/schemas/sitemap/0.84"">"
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" &amp;amp; strURL &amp;amp; "/</loc> "
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
set all_fs = Server.CreateObject("Scripting.FileSystemObject")
set all_folder = all_fs.GetFolder(server.MapPath("/"))
set all_files = all_folder.files
for each file in all_files
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" &amp;amp; strURL &amp;amp; "/" &amp;amp; File.Name &amp;amp; "</loc> "
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
next
dim js,sql
set js = server.CreateObject("ADODB.RecordSet")
sql = "select * from [要生成的表名] order by sid asc"    //修改你要生成的数据表名
set js = conn.execute (sql)
do until js.eof
id=""&amp;amp;js("id")&amp;amp;""   //修改为你的id字段
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" &amp;amp; strURL &amp;amp; "/xxx.asp?Id=" &amp;amp; id &amp;amp; "</loc> "  //修改为你的文件名称和id
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
js.movenext
loop
js.close
set js = nothing
foolcat = foolcat + "</urlset>"
foolcat = "" + foolcat + ""
foolcat = "" &amp;amp; foolcat &amp;amp; ""
FolderPath = Server.MapPath("/")
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(FolderPath&amp;amp;"&amp;#92;sitemap.xml")
fout.writeLine foolcat
fout.close
set fout = nothing
conn.close
set conn = nothing
Function return_RFC822_Date(byVal myDate, byVal TimeZone)
Dim myDay, myDays, myMonth, myYear
Dim myHours, myMinutes, mySeconds
  
myDate = CDate(myDate)
myDay = EnWeekDayName(myDate)
myDays = Right("00" &amp;amp; Day(myDate),2)
myMonth = EnMonthName(myDate)
myYear = Year(myDate)
myHours = Right("00" &amp;amp; Hour(myDate),2)
myMinutes = Right("00" &amp;amp; Minute(myDate),2)
mySeconds = Right("00" &amp;amp; Second(myDate),2)
  
return_RFC822_Date = myDay&amp;amp;", "&amp;amp; _
myDays&amp;amp;" "&amp;amp; _
myMonth&amp;amp;" "&amp;amp; _
myYear&amp;amp;" "&amp;amp; _
myHours&amp;amp;":"&amp;amp; _
myMinutes&amp;amp;":"&amp;amp; _
mySeconds&amp;amp;" "&amp;amp; _
" " &amp;amp; TimeZone
End Function
Function EnWeekDayName(InputDate)
Dim Result
Select Case WeekDay(InputDate,1)
Case 1:Result="Sun"
Case 2:Result="Mon"
Case 3:Result="Tue"
Case 4:Result="Wed"
Case 5:Result="Thu"
Case 6:Result="Fri"
Case 7:Result="Sat"
End Select
EnWeekDayName = Result
End Function
Function EnMonthName(InputDate)
Dim Result
Select Case Month(InputDate)
Case 1:Result="Jan"
Case 2:Result="Feb"
Case 3:Result="Mar"
Case 4:Result="Apr"
Case 5:Result="May"
Case 6:Result="Jun"
Case 7:Result="Jul"
Case 8:Result="Aug"
Case 9:Result="Sep"
Case 10:Result="Oct"
Case 11:Result="Nov"
Case 12:Result="Dec"
End Select
EnMonthName = Result
End Function
%>
[/code]

sitemap.xml生成完毕,共生成<%=session("count")%>个文件,点击查看sitemap.xml文件。

本文固定链接: http://www.zhzx.info/archives/130 | 赵泽鑫'S Blog

该日志由 赵泽鑫 于2008年04月23日发表在 胡说八道 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 专门为google量身定做的sitemap生成代码(动态) | 赵泽鑫'S Blog

专门为google量身定做的sitemap生成代码(动态):等您坐沙发呢!

发表评论

您必须 [ 登录 ] 才能发表留言!