直接生成XML的Google SiteMap的asp代码
作者:Francesco Passantino 来源:iteam5.net 发布时间:2007-08-17 13:44:00
下面提供生成XML的Google SiteMap代码[ASP版本]。
这个代码是生成全站文件链接的地图:
<%
Server.ScriptTimeout=50000
' sitemap_gen.asp
' A simple script to automatically produce sitemaps for a webserver, in the Google Sitemap Protocol (GSP)
' by Francesco Passantino
' www.iteam5.net/francesco/sitemap
' v0.2 released 5 june 2005 (Listing a directory tree recursively improvement)
'
' BSD 2.0 license,
' http://www.opensource.org/licenses/bsd-license.php
session("server")="http://www.aspxhome.com" '你的域名
vDir = "/" '制作SiteMap的目录,相对目录(相对于根目录而言)
set objfso = CreateObject("Scripting.FileSystemObject")
root = Server.MapPath(vDir)
'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='UTF-8'?>" & 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
'response.write getfilelink(objFile.Path,objfile.dateLastModified)
str = str & getfilelink(objFile.Path,objfile.dateLastModified) & vbcrlf
Next
ShowSubFolders(objFolder)
'response.write "</urlset>"
str = str & "</urlset>" & vbcrlf
set fso = nothing
Set objStream = Server.CreateObject("ADODB.Stream")
With objStream
'.Type = adTypeText
'.Mode = adModeReadWrite
.Open
.Charset = "utf-8"
.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
'response.write getfilelink(objSubFolder.Path,objSubFolder.dateLastModified)
str = str & getfilelink(objSubFolder.Path,objSubFolder.dateLastModified) & vbcrlf
Set colFiles = objSubFolder.Files
For Each objFile In colFiles
'response.write getfilelink(objFile.Path,objFile.dateLastModified)
str = str & getfilelink(objFile.Path,objFile.dateLastModified) & vbcrlf
Next
ShowSubFolders(objSubFolder)
end if
Next
End Sub
Function getfilelink(file,datafile)
file=replace(file,root,"")
file=replace(file,"\","/")
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(session("server")&vDir&file)&"</loc><lastmod>"&filedate&"</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>"
Response.Flush
End Function
Function Folderpermission(pathName)
'需要过滤的目录(不列在SiteMap里面)
PathExclusion=Array("\temp","\_vti_cnf","_vti_pvt","_vti_log","cgi-bin","\admin","\edu")
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
'modify for your file extension (http://www.googleguide.com/file_type.html)
Extensions = Array("png","gif","jpg","jpeg","zip","pdf","ps","html","htm","php","wk1","wk2","wk3","wk4","wk5","wki","wks","wku","lwp","mw","xls","ppt","doc","swf","wks","wps","wdb","wri","rtf","ans","txt")
'设置列表的文件名,扩展名不在其中的话SiteMap则不会收录该扩展名的文件
if len(trim(sFileName)) = 0 then
FileExtensionIsBad = true
Exit Function
end if
sFileExtension = right(sFileName, len(sFileName) - instrrev(sFileName, "."))
bFileExtensionIsValid = false 'assume extension is bad
for each sFileExt in extensions
if ucase(sFileExt) = ucase(sFileExtension) then
bFileExtensionIsValid = True
exit for
end if
next
FileExtensionIsBad = not bFileExtensionIsValid
End Function
%>


猜你喜欢
- 1.DNS查询过程:以查询 www.baidu.com为例(1)电脑向本地域名服务器发送解析www.baidu.com的请求(2)本地域名服
- google 的设计原则中文1.易用性-聚焦在人,方便他们的生活,工作,梦想。2.速度-分秒必争3.简单-简单而强有力4.关联性- 对初学者
- 首先我们看公式:这个是要拟合的函数然后我们求出它的损失函数, 注意:这里的n和m均为数据集的长度,写的时候忘了注意,前面的theta0-th
- 今天开始学习Python时发现Pycharm竟然过期了需要重新注册,穷苦学生没钱只能再找找百度了浪费了半天时间终于找到一个可以使用的了,支持
- 一、实验目的实现学生选课系统二、实验环境Python3.6pymysql(Python连接MySQL)xlrd(操作Excel)三、程序结构
- 本文实例为大家分享了js实现select二级联动下拉菜单,供大家参考,具体内容如下<%@ page language="ja
- 最近在研究WEB布局,遇到<H1>标签了,<H1>标签很重要。在一般教程中都这么说,<H1>标签在同一页
- MySQL 拥有一个复杂的但直观易学的 SQL 接口。这个章节描述了各种不同的命令、类型和函数,为了高效地使用 MySQL 需要了解它们。这
- 以前写过一篇:python实现把两个二维array叠加成三维array示例这篇文章尝试用“曲线救国”的方法来解决二维数组叠加成三维数组的问题
- 字典排序在程序中使用字典进行数据信息统计时,由于字典是无序的所以打印字典时内容也是无序的。因此,为了使统计得到的结果更方便查看需要进行排序。
- 1. 关于列表更多的内容Python 的列表数据类型包含更多的方法。这里是所有的列表对象方法:list.``append(x)把一个元素添加
- 前言:vue 中路由(router)的功能就是:把 url 与 应用中的对应的组件进行关联,通过不同的 url 访问不同的组件。但是如果我们
- 用js封装一些常用的jquery方法 记录一下hasClass:判断是否有classfunction hasClass(ele, cls)
- 前言在网上找了很多Python处理Excel的方法和代码,都不是很尽人意,所以自己综合网上各位大佬的方法,自己进行了优化,具体的代码如下。博
- 机器学习分两大类,有监督学习(supervised learning)和无监督学习(unsupervised learning)。有监督学习
- 在这篇文章中,将向您展示如何使用Python链接目前主流的MongoDB(V3.4.0)数据库,主要使用PyMongo(v3.4.0)和Mo
- 开发客户端客户是持有TPCoins并从网络上的其他供应商处交换商品/服务的客户,包括他自己的.我们应该为此目的定义 Client&
- 一、表示修饰符。可以在模块或者类的定义层内对函数进行修饰。出现在函数定义的前一行,不允许和函数定义在同一行。一个修饰符就是一个函数,它将被修
- TRUNCATE TABLE (Transact-SQL)Removes all rows from a table without log
- 1. 安装 Git在 Windows 系统中安装Git非常简单,只需要下载Git的安装包,然后安装引导点击安装即可:Git下载地址:http