小Tan工作室导航: 首页 博客 赛车 新闻 视频 游戏 音乐 小说 电视 下载 域名 邮箱 英文

利用Google Sitemap更好的收录网站



要让你的网站快速被Google收录,使用Google Sitemap是一个很好的方法。
Sitemap使用xml格式来记录整个网站的信息并供Google读取,只要网站有更新就会自动通知google。这样一来,搜索引擎的收录由被动的pull变成了主动的push,辛苦的google爬虫们终于可以松一口气了。
登录 http://www.google.com/webmasters/sitemaps 提交xml文件就可以了。登录时使用你的Gmail帐号就即可。

下面提供一个asp网站的sitemap.xml文件生成器。将以下代码存为.asp文件上传至服务器后访问该文件就可以了。
程序代码 程序代码
<%
Server.ScriptTimeout=50000
dim seoDir
session("server")="http://jefftan.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='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
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 = "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
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

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")&seoDir&file)

&"</loc><lastmod>"&filedate&"</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>"
Response.Flush
End Function

Function Folderpermission(pathName)
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
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","asp")
'设置列表的文件名,扩展名不在其中的话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
%>

我测试了一下这段代码,并不是百分之百的理想,对于具体情况需要作一些小的修改。
比如我粘贴源码到jefftan.cn中运行,得到的xml文件中的路径都是 jefftan.cn//***.asp 。域名后面多了一个左斜线。解决的办法是修改下面的代码片段。
程序代码 程序代码
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")&seoDir&file)

这个片段在全部代码的中段附近。将最后一行的 &seoDir 去掉就可以了。

有些时候问题更加严重,出来的结果路径完全不正确,建议在上面片段中的第三行后添加
程序代码 程序代码
%><%=file%><br><%

这样,运行.asp文件时同时显示出一长串路径代码。正确的情况应该是由根目录出发的文件路径,如根目录下的help.asp即显示help.asp。若显示/help.asp则直接去掉 &seoDir 即可。若出现多的部分,则需要对第二行进行修改。比如显示 D:\wwwroot\jefftan\wwwroot\help.asp 则将第二行改为
程序代码 程序代码
file=replace(file,"D:\wwwroot\jefftan\wwwroot\","")

这样就删去了多余的部分。重新运行就可以了。


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: Google Sitemap xml 网站
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.