生成网站地图的代码,ASP,PHP都行
应该有免费了的吧? <%Server.ScriptTimeout=50000
dim seoDir
kczm="http://www.syrcw.cn" '把该网址改成自己网站的
seoDir="/"
set objfso = CreateObject("Scripting.FileSystemObject")
root = Server.MapPath(seoDir)
'response.ContentType = "text/xml"
'response.write "<?xml version='1.0' encoding='UTF-8'?>"
'response.write "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84';>"
str = "<?xml version='1.0' encoding='gb2312'?>" & vbcrlf
str = str & "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>" & vbcrlf
Set objFolder = objFSO.GetFolder(root)
'response.write getfilelink(objFolder.Path,objFolder.dateLastModified)
Set colFiles = objFolder.Files
For Each objFile In colFiles
str=str & getfilelink(objFile.Path,objfile.dateLastModified) & vbcrlf
Next
ShowSubFolders(objFolder)
str = str & "</urlset>" & vbcrlf
set fso = nothing
Set objStream = Server.CreateObject("ADODB.Stream")
With objStream
.Open
.Charset = "gb2312"
.Position = objStream.Size
.WriteText=str
.SaveToFile server.mappath("/sitemap.xml"),2 '生成的XML文件名
.Close
End With
Set objStream = Nothing
If Not Err Then
Response.Write("<script>alert('成功生成站点地图!');history.back();</script>")
Response.End
End If
Sub ShowSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
if folderpermission(objSubFolder.Path) then
str = str & getfilelink(objSubFolder.Path,objSubFolder.dateLastModified) & vbcrlf
Set colFiles = objSubFolder.Files
For Each objFile In colFiles
str = str & getfilelink(objFile.Path,objFile.dateLastModified) & vbcrlf
Next
ShowSubFolders(objSubFolder)
end if
Next
End Sub
dim pro
dim inde
Function getfilelink(file,datafile)
file=replace(file,root,"")
file=replace(file,"\","/")
pro="liushuixian"
inde="index.html"
if instr(file,inde)>0 then
cccc="1.0"
else
if instr(file,pro)>0 then
cccc="0.9"
else
cccc="0.8"
end if
end if
file=replace(file,wangmin,"")
If FileExtensionIsBad(file) then Exit Function
if month(datafile)<10 then filedatem="0"
if day(datafile)<10 then filedated="0"
filedate=year(datafile)&"-"&filedatem&month(datafile)&"-"&filedated&day(datafile)
getfilelink = "<url><loc>"&server.htmlencode(kczm&file)&"</loc><lastmod>"&filedate&"</lastmod><changefreq>daily</changefreq><priority>"&cccc&"</priority></url>"
Response.Flush
End Function
Function Folderpermission(pathName)
PathExclusion=Array("\admin")
Folderpermission =True
for each PathExcluded in PathExclusion
if instr(ucase(pathName),ucase(PathExcluded))>0 then
Folderpermission = False
exit for
end if
next
End Function
Function FileExtensionIsBad(sFileName)
Dim sFileExtension, bFileExtensionIsValid, sFileExt
Extensions = Array("html")
'设置列表的文件名,扩展名不在其中的话SiteMap则不会收录该扩展名的文件
if len(trim(sFileName)) = 0 then
FileExtensionIsBad=true
Exit Function
end if
sFileExtension = right(sFileName, len(sFileName) - instrrev(sFileName, "."))
bFileExtensionIsValid=false
for each sFileExt in extensions
if ucase(sFileExt)=ucase(sFileExtension) then
bFileExtensionIsValid=True
exit for
end if
next
FileExtensionIsBad = not bFileExtensionIsValid
End Function
%> 留个脚印,收藏了
回复 2楼 潇湘 的帖子
谢了,还是邵阳老乡 *** 作者被禁止或删除 内容自动屏蔽 *** Parse error: syntax error, unexpected T_STRING in /dt.php on line 18 PM偶你邮箱,偶给你 踩一脚,收藏了 不错 :lol: 这个只能生成一个文件吧? 做个记号页:
[1]
