为google量身定做的sitemap生成代码asp版
程序员文章站
2022-05-31 12:41:44
外面很多所谓sitemap生成代码都只生成目录文件地址,没生成动态的,我后来自己写了这个,是支持动态的,例子: 如你是文章网站,文章有2000条,那你修改下对应你的文章数据...
外面很多所谓sitemap生成代码都只生成目录文件地址,没生成动态的,我后来自己写了这个,是支持动态的,例子: 如你是文章网站,文章有2000条,那你修改下对应你的文章数据表,即可生成除了所有目录文件外,还生成你的动态2000条地址,绝对的没话说,生成速度非常快
把下面代码保存为sitemap.asp文件,修改我已注明的几个地方,其他的一概不要修改,好不好用过才知道。
<!--#include file="conn.asp"-->
<%
session("count")=0
strurl = "http://" & request.servervariables("server_name") & _
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 " & return_rfc822_date(now,"gmt") & "-->"
foolcat = foolcat + "<urlset xmlns=""http://www.google.com/schemas/sitemap/0.84"">"
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" & strurl & "/</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>" & strurl & "/" & file.name & "</loc> "
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
next
dim js,sql
set js = server.createobject("adodb.recordset")
sql = "select * from [要生成的表名] order by id asc" //修改你要生成的数据表名
set js = conn.execute (sql)
do until js.eof
id=""&js("id")"" //修改为你的id字段
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" & strurl & "/xxx.asp?id=" & id & "</loc> " //修改为你的文件名称和id
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
js.movenext
loop
js.close
set js = nothing
foolcat = foolcat + "</urlset>"
foolcat = "" + foolcat + ""
foolcat = "" & foolcat & ""
folderpath = server.mappath("/")
set fso = server.createobject("scripting.filesystemobject")
set fout = fso.createtextfile(folderpath"\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" & day(mydate),2)
mymonth = enmonthname(mydate)
myyear = year(mydate)
myhours = right("00" & hour(mydate),2)
myminutes = right("00" & minute(mydate),2)
myseconds = right("00" & second(mydate),2)
return_rfc822_date = myday", "& _
mydays" "& _
mymonth" "& _
myyear" "& _
myhours":"& _
myminutes":"& _
myseconds" "& _
" " & 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
%>
把下面代码保存为sitemap.asp文件,修改我已注明的几个地方,其他的一概不要修改,好不好用过才知道。
复制代码 代码如下:
<!--#include file="conn.asp"-->
<%
session("count")=0
strurl = "http://" & request.servervariables("server_name") & _
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 " & return_rfc822_date(now,"gmt") & "-->"
foolcat = foolcat + "<urlset xmlns=""http://www.google.com/schemas/sitemap/0.84"">"
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" & strurl & "/</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>" & strurl & "/" & file.name & "</loc> "
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
next
dim js,sql
set js = server.createobject("adodb.recordset")
sql = "select * from [要生成的表名] order by id asc" //修改你要生成的数据表名
set js = conn.execute (sql)
do until js.eof
id=""&js("id")"" //修改为你的id字段
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" & strurl & "/xxx.asp?id=" & id & "</loc> " //修改为你的文件名称和id
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
js.movenext
loop
js.close
set js = nothing
foolcat = foolcat + "</urlset>"
foolcat = "" + foolcat + ""
foolcat = "" & foolcat & ""
folderpath = server.mappath("/")
set fso = server.createobject("scripting.filesystemobject")
set fout = fso.createtextfile(folderpath"\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" & day(mydate),2)
mymonth = enmonthname(mydate)
myyear = year(mydate)
myhours = right("00" & hour(mydate),2)
myminutes = right("00" & minute(mydate),2)
myseconds = right("00" & second(mydate),2)
return_rfc822_date = myday", "& _
mydays" "& _
mymonth" "& _
myyear" "& _
myhours":"& _
myminutes":"& _
myseconds" "& _
" " & 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
%>
上一篇: asp下去除超链接的函数
下一篇: 4个超神工作表技巧,还不快学起来!