本來使用那些網站生成google網站地圖,時間久了,感覺太麻煩了:先打開他們的網站,輸入我的網址,然後點擊生成,等待一段時間後,下載生成後的文件,再將它通過FTP上傳到空間上了。實在太麻煩了,還不如自己用ASP去寫一個。
把下面代碼保存為sitemap.ASP文件
001
<!--#include file=
"conn.ASP"
-->
002
<%
003
session(
"count"
)=0
004
strURL =
"http://"
& request.servervariables(
"SERVER_NAME"
) & _
005
left(request.servervariables(
"SCRIPT_NAME"
),len(request.servervariables(
"SCRIPT_NAME"
))-len(
"/sitemap.ASP"
))
006
dim foolcat
007
foolcat = foolcat +
"<?XML version="
"1.0"
" encoding="
"UTF-8"
"?>"
008
foolcat = foolcat +
"<!--Google Site Map File Generated by http://www.xxx.com "
& return_RFC822_Date(now,
"GMT"
) &
"-->"
009
foolcat = foolcat +
"<urlset XMLns="
"http://www.google.com/schemas/sitemap/0.84"
">"
010
foolcat = foolcat +
"<url>"
011
foolcat = foolcat +
"<loc>"
& strURL &
"/</loc> "
012
foolcat = foolcat +
"</url>"
013
session(
"count"
)=session(
"count"
)+
"1"
014
set all_fs = Server.CreateObject(
"Scripting.FileSystemObject"
)
015
set all_folder = all_fs.GetFolder(server.MapPath(
"/"
))
016
set all_files = all_folder.files
017
for each file in all_files
018
foolcat = foolcat +
"<url>"
019
foolcat = foolcat +
"<loc>"
& strURL &
"/"
& File.Name &
"</loc> "
020
foolcat = foolcat +
"</url>"
021
session(
"count"
)=session(
"count"
)+
"1"
022
next
023
dim JS,sql
024
set JS = server.CreateObject(
"ADODB.RecordSet"
)
025
sql =
"select * from [要生成的表名] order by sid asc"
//修改你要生成的數據表名
026
set JS = conn.execute (sql)
027
do until JS.eof
028
id=
""
&JS(
"id"
)&
""
//修改為你的id字段
029
foolcat = foolcat +
"<url>"
030
foolcat = foolcat +
"<loc>"
& strURL &
"/xxx.ASP?Id="
& id &
"</loc> "
//修改為你的文件名稱和id
031
foolcat = foolcat +
"</url>"
032
session(
"count"
)=session(
"count"
)+
"1"
033
JS.movenext
034
loop
035
JS.close
036
set JS = nothing
037
foolcat = foolcat +
"</urlset>"
038
foolcat =
""
+ foolcat +
""
039
foolcat =
""
& foolcat &
""
040
FolderPath = Server.MapPath(
"/"
)
041
Set
fso = Server.CreateObject(
"Scripting.FileSystemObject"
)
042
Set
fout = fso.CreateTextFile(FolderPath&
"\sitemap.XML"
)
043
fout.writeLine foolcat
044
fout.close
045
set fout = nothing
046
conn.close
047
set conn = nothing
048
Function
return_RFC822_Date(byVal myDate, byVal TimeZone)
049
Dim
myDay, myDays, myMonth, myYear
050
Dim
myHours, myMinutes, mySeconds
051
052
myDate =
CDate
(myDate)
053
myDay = EnWeekDayName(myDate)
054
myDays = Right(
"00"
& Day(myDate),2)
055
myMonth = EnMonthName(myDate)
056
myYear = Year(myDate)
057
myHours = Right(
"00"
& Hour(myDate),2)
058
myMinutes = Right(
"00"
& Minute(myDate),2)
059
mySeconds = Right(
"00"
& Second(myDate),2)
060
061
return_RFC822_Date = myDay&
", "
& _
062
myDays&
" "
& _
063
myMonth&
" "
& _
064
myYear&
" "
& _
065
myHours&
":"
& _
066
myMinutes&
":"
& _
067
mySeconds&
" "
& _
068
" "
& TimeZone
069
End
Function
070
Function
EnWeekDayName(InputDate)
071
Dim
Result
072
Select
Case
WeekDay(InputDate,1)
073
Case
1:Result=
"Sun"
074
Case
2:Result=
"Mon"
075
Case
3:Result=
"Tue"
076
Case
4:Result=
"Wed"
077
Case
5:Result=
"Thu"
078
Case
6:Result=
"Fri"
079
Case
7:Result=
"Sat"
080
End
Select
081
EnWeekDayName = Result
082
End
Function
083
Function
EnMonthName(InputDate)
084
Dim
Result
085
Select
Case
Month(InputDate)
086
Case
1:Result=
"Jan"
087
Case
2:Result=
"Feb"
088
Case
3:Result=
"Mar"
089
Case
4:Result=
"Apr"
090
Case
5:Result=
"May"
091
Case
6:Result=
"Jun"
092
Case
7:Result=
"Jul"
093
Case
8:Result=
"Aug"
094
Case
9:Result=
"Sep"
095
Case
10:Result=
"Oct"
096
Case
11:Result=
"Nov"
097
Case
12:Result=
"Dec"
098
End
Select
099
EnMonthName = Result
100
End
Function
101
%>
(鼠標移到代碼上去,在代碼的頂部會出現四個圖標,第一個是查看源代碼,第二個是復制代碼,第三個是打印代碼,第四個是幫助)sitemap.xml生成完畢,共生成<%=session("count")%>個文件,點擊查看<a href="sitemap.xml">sitemap.XML</a>文件。