posts - 22, comments - 20, trackbacks - 1, articles - 3

导航

公告

Google SiteMap的作用及协议格式详解

Posted on 2006-11-21 11:23 cowboy 阅读(...) 评论(...) 编辑 收藏
Google SiteMap Protocol是Google自己推出的一种站点地图协议,此协议文件基于早期的robots.txt文件协议,并有所升级。在Google官方指南中指出加入了Google SiteMap文件的网站将更有利于Google网页爬行机器人的爬行索引,这样将提高索引网站内容的效率和准确度。文件协议应用了简单的XML格式,一共用到6个标签,其中关键标签包括链接地址、更新时间、更新频率和索引优先权。 Google SiteMap文件生成后格式如下: http://duduwolf.winzheng.com 2005-06-03T04:20-08:00 always 1.0 http://duduwolf.winzheng.com/post/140.html 2005-06-02T20:20:36Z daily 0.8 XML标签 changefreq:页面内容更新频率。 lastmod:页面最后修改时间 loc:页面永久链接地址 priority:相对于其他页面的优先权 url:相对于前4个标签的父标签 urlset:相对于前5个标签的父标签 我将一句一句分解讲解这个xml文件的每一个标签: 这一行定义了此xml文件的命名空间,相当于网页文件中的标签一样的作用。 这是具体某一个链接的定义入口,你所希望展示在SiteMap文件中的每一个链接都要用包含在里面,这是必须的。 http://duduwolf.winzheng.com描述出具体的链接地址,这里需要注意的是链接地址中的一些特殊字符必须转换为XML(HTML)定义的转义字符,如下表: 字符转义后的字符 HTML字符字符编码 and(和)&&& 单引号''' 双引号""" 大于号>>> 小于号<<< 2005-06-03T04:20:32-08:00 是用来指定该链接的最后更新时间,这个很重要。Google的机器人会在索引此链接前先和上次索引记录的最后更新时间进行比较,如果时间一样就会跳过不再索引。所以如果你的链接内容基于上次Google索引时的内容有所改变,应该更新该时间,让Google下次索引时会重新对该链接内容进行分析和提取关键字。这里必须用ISO 8601中指定的时间格式进行描述,格式化的时间格式如下: 年:YYYY(2005) 年和月:YYYY-MM(2005-06) 年月日:YYYY-MM-DD(2005-06-04) 年月日小时分钟:YYYY-MM-DDThh:mmTZD(2005-06-04T10:37+08:00) 年月日小时分钟秒:YYYY-MM-DDThh:mmTZD(2005-06-04T10:37:30+08:00) 这里需注意的是TZD,TZD指定就是本地时间区域标记,像中国就是+08:00了 always 用这个标签告诉Google此链接可能会出现的更新频率,比如首页肯定就要用always(经常),而对于很久前的链接或者不再更新内容的链接就可以用yearly(每年)。这里可以用来描述的单词共这几个:"always", "hourly", "daily", "weekly", "monthly", "yearly",具体含义我就不用解释了吧,光看单词的意思就明白了。 1.0 是用来指定此链接相对于其他链接的优先权比值,此值定于0.0 - 1.0之间 还有,这两个就是来关闭xml标签的,这和HTML中的和是一个道理 另外需要注意的是,这个xml文件必须是utf-8的编码格式,不管你是手动生成还是通过代码生成,建议最好检查一下xml文件是否是utf-8编码,最简单的方法就是用记事本打开xml然后另存为时选择编码(或转换器)为UTF-8。 z-blog系统和Wordpress系统的自动生成SiteMap程序及详细生成后代码 z-blog: <%@ CODEPAGE=65001 %> <% Option Explicit %> <% On Error Resume Next %> <% Response.Charset="UTF-8" %> <% Response.Buffer=True %> <!-- #include file="c_option.asp" --> <!-- #include file="c_function.asp" --> <!-- #include file="c_system_lib.asp" --> <!-- #include file="c_system_base.asp" --> <% If Request.ServerVariables("REQUEST_METHOD")="POST" Then Dim str, Conn, Rs, objStream Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &amp;amp;amp;amp;amp;amp;amp;amp; BlogPath &amp;amp;amp;amp;amp;amp;amp;amp; "/" &amp;amp;amp;amp;amp;amp;amp;amp; ZC_DATABASE_PATH str = "" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp; ZC_BLOG_HOST &amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; FormatDate("YYYY-MM-DD",Date()) &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "always" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "0.9" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf Set Rs = Conn.Execute("select * from blog_Article where log_Level=4 order by log_PostTime desc") Do While Not Rs.Eof str = str &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; ZC_BLOG_HOST &amp;amp;amp;amp;amp;amp;amp;amp; "post/" &amp;amp;amp;amp;amp;amp;amp;amp; Rs("log_ID") &amp;amp;amp;amp;amp;amp;amp;amp; "." &amp;amp;amp;amp;amp;amp;amp;amp; ZC_STATIC_TYPE &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; FormatDate("YYYY-MM-DD", Rs("log_PostTime")) &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "daily" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "0.8" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf str = str &amp;amp;amp;amp;amp;amp;amp;amp; "" &amp;amp;amp;amp;amp;amp;amp;amp; vbcrlf Rs.MoveNext Loop Rs.Close Set Rs = Nothing Set Conn = Nothing str = str &amp;amp;amp;amp;amp;amp;amp;amp; "" Set objStream = Server.CreateObject("ADODB.Stream") With objStream .Type = adTypeText .Mode = adModeReadWrite .Open .Charset = "utf-8" .Position = objStream.Size .WriteText=str .SaveToFile BlogPath &amp;amp;amp;amp;amp;amp;amp;amp; "/googlesitemap.xml",adSaveCreateOverWrite .Close End With Set objStream = Nothing If Not Err Then Response.Write("") Response.End End If End If Function FormatDate(FormatStr, CurDateTime) Dim sTemp,YYYY,YY,MM,DD,HH,mmm,SS sTemp = FormatStr If IsDate(CurDateTime) Then YYYY = Year(CurDateTime) YY = Mid(Year(CurDateTime),3,2) MM = Month(CurDateTime) If CInt(MM) <10 Then MM = "0"&amp;amp;amp;amp;amp;amp;amp;amp;MM DD = Day(CurDateTime) If CInt(DD) <10 Then DD = "0"&amp;amp;amp;amp;amp;amp;amp;amp;DD HH = Hour(CurDateTime) If CInt(HH) <10 Then HH = "0"&amp;amp;amp;amp;amp;amp;amp;amp;DD mmm = Minute(CurDateTime)+1 If CInt(mmm) <10 Then mmm = "0"&amp;amp;amp;amp;amp;amp;amp;amp;mmm SS = Second(CurDateTime) If CInt(SS) <10 Then SS = "0"&amp;amp;amp;amp;amp;amp;amp;amp;SS sTemp = Replace(Replace(Replace(Replace(Replace(Replace(Replace(sTemp, "YYYY", YYYY), "YY", YY), "MM", MM), "DD", DD), "HH", HH), "mm", mmm), "SS", SS) End If If IsDate(sTemp) Then FormatDate = sTemp Else FormatDate = CurDateTime End If End Function %>
Wordpress: '; ?> " target="_blank">http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"> always 1.0 get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'publish' ORDER by post_modified DESC"); ?> ID); ?> post_modified, false); ?> daily 0.8 我的站点地图文件(http://duduwolf.winzheng.com/googlesitemap.xml): " target="_blank">http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"> http://duduwolf.winzheng.com/ 2005-06-04 always 0.9 http://duduwolf.winzheng.com/post/150.html 2005-06-04 daily 0.8 http://duduwolf.winzheng.com/post/149.html 2005-06-03 daily 0.8 http://duduwolf.winzheng.com/post/143.html 2005-06-03 daily 0.8 http://duduwolf.winzheng.com/post/142.html 2005-06-02 daily 0.8 http://duduwolf.winzheng.com/post/139.html 2005-06-01 daily 0.8 http://duduwolf.winzheng.com/post/138.html 2005-06-01 daily 0.8 http://duduwolf.winzheng.com/post/137.html 2005-05-31 daily 0.8 http://duduwolf.winzheng.com/post/136.html 2005-05-30 daily 0.8 http://duduwolf.winzheng.com/post/135.html 2005-05-30 daily 0.8 http://duduwolf.winzheng.com/post/134.html 2005-05-28 daily 0.8 http://duduwolf.winzheng.com/post/133.html 2005-05-28 daily 0.8 http://duduwolf.winzheng.com/post/132.html 2005-05-28 daily 0.8 http://duduwolf.winzheng.com/post/131.html 2005-05-27 daily 0.8 http://duduwolf.winzheng.com/post/130.html 2005-05-27 daily 0.8 http://duduwolf.winzheng.com/post/129.html 2005-05-26 daily 0.8 http://duduwolf.winzheng.com/post/128.html 2005-05-25 daily 0.8 http://duduwolf.winzheng.com/post/127.html 2005-05-24 daily 0.8 http://duduwolf.winzheng.com/post/126.html 2005-05-24 daily 0.8 http://duduwolf.winzheng.com/post/125.html 2005-05-23 daily 0.8 http://duduwolf.winzheng.com/post/124.html 2005-05-23 daily 0.8 http://duduwolf.winzheng.com/post/123.html 2005-05-23 daily 0.8 http://duduwolf.winzheng.com/post/122.html 2005-05-22 daily 0.8 http://duduwolf.winzheng.com/post/121.html 2005-05-21 daily 0.8 http://duduwolf.winzheng.com/post/120.html 2005-05-20 daily 0.8 http://duduwolf.winzheng.com/post/119.html 2005-05-18 daily 0.8 http://duduwolf.winzheng.com/post/118.html 2005-05-18 daily 0.8 http://duduwolf.winzheng.com/post/117.html 2005-05-18 daily 0.8 http://duduwolf.winzheng.com/post/116.html 2005-05-18 daily 0.8 http://duduwolf.winzheng.com/post/115.html 2005-05-17 daily 0.8 http://duduwolf.winzheng.com/post/114.html 2005-05-17 daily 0.8 http://duduwolf.winzheng.com/post/113.html 2005-05-17 daily 0.8 http://duduwolf.winzheng.com/post/112.html 2005-05-14 daily 0.8 http://duduwolf.winzheng.com/post/111.html 2005-05-13 daily 0.8 http://duduwolf.winzheng.com/post/110.html 2005-05-12 daily 0.8 http://duduwolf.winzheng.com/post/109.html 2005-05-12 daily 0.8 http://duduwolf.winzheng.com/post/108.html 2005-05-11 daily 0.8 http://duduwolf.winzheng.com/post/107.html 2005-05-10 daily 0.8 http://duduwolf.winzheng.com/post/103.html 2005-05-10 daily 0.8 http://duduwolf.winzheng.com/post/102.html 2005-05-10 daily 0.8 http://duduwolf.winzheng.com/post/100.html 2005-05-08 daily 0.8 http://duduwolf.winzheng.com/post/99.html 2005-05-07 daily 0.8 http://duduwolf.winzheng.com/post/98.html 2005-05-07 daily 0.8 http://duduwolf.winzheng.com/post/97.html 2005-05-05 daily 0.8 http://duduwolf.winzheng.com/post/96.html 2005-05-05 daily 0.8 http://duduwolf.winzheng.com/post/95.html 2005-04-30 daily 0.8 http://duduwolf.winzheng.com/post/94.html 2005-04-28 daily 0.8 http://duduwolf.winzheng.com/post/93.html 2005-04-27 daily 0.8 http://duduwolf.winzheng.com/post/92.html 2005-04-27 daily 0.8 http://duduwolf.winzheng.com/post/91.html 2005-04-26 daily 0.8 http://duduwolf.winzheng.com/post/90.html 2005-04-26 daily 0.8 http://duduwolf.winzheng.com/post/89.html 2005-04-26 daily 0.8 http://duduwolf.winzheng.com/post/88.html 2005-04-26 daily 0.8 http://duduwolf.winzheng.com/post/87.html 2005-04-21 daily 0.8 http://duduwolf.winzheng.com/post/86.html 2005-04-21 daily 0.8 http://duduwolf.winzheng.com/post/85.html 2005-04-19 daily 0.8 http://duduwolf.winzheng.com/post/84.html 2005-04-18 daily 0.8 http://duduwolf.winzheng.com/post/83.html 2005-04-18 daily 0.8 http://duduwolf.winzheng.com/post/82.html 2005-04-18 daily 0.8 http://duduwolf.winzheng.com/post/81.html 2005-04-17 daily 0.8 http://duduwolf.winzheng.com/post/80.html 2005-04-15 daily 0.8 http://duduwolf.winzheng.com/post/79.html 2005-04-15 daily 0.8 http://duduwolf.winzheng.com/post/78.html 2005-04-13 daily 0.8 http://duduwolf.winzheng.com/post/77.html 2005-04-13 daily 0.8 http://duduwolf.winzheng.com/post/76.html 2005-04-13 daily 0.8 http://duduwolf.winzheng.com/post/75.html 2005-04-12 daily 0.8 http://duduwolf.winzheng.com/post/74.html 2005-04-11 daily 0.8 http://duduwolf.winzheng.com/post/73.html 2005-04-10 daily 0.8 http://duduwolf.winzheng.com/post/71.html 2005-04-08 daily 0.8 http://duduwolf.winzheng.com/post/72.html 2005-04-07 daily 0.8 http://duduwolf.winzheng.com/post/70.html 2005-04-07 daily 0.8 http://duduwolf.winzheng.com/post/69.html 2005-04-07 daily 0.8 http://duduwolf.winzheng.com/post/68.html 2005-04-04 daily 0.8 http://duduwolf.winzheng.com/post/67.html 2005-04-03 daily 0.8 http://duduwolf.winzheng.com/post/61.html 2005-04-03 daily 0.8 http://duduwolf.winzheng.com/post/60.html 2005-04-01 daily 0.8 http://duduwolf.winzheng.com/post/59.html 2005-04-01 daily 0.8 http://duduwolf.winzheng.com/post/58.html 2005-03-30 daily 0.8 http://duduwolf.winzheng.com/post/57.html 2005-03-30 daily 0.8 http://duduwolf.winzheng.com/post/55.html 2005-03-29 daily 0.8 http://duduwolf.winzheng.com/post/53.html 2005-03-26 daily 0.8 http://duduwolf.winzheng.com/post/52.html 2005-03-23 daily 0.8 http://duduwolf.winzheng.com/post/51.html 2005-03-23 daily 0.8 http://duduwolf.winzheng.com/post/50.html 2005-03-21 daily 0.8 http://duduwolf.winzheng.com/post/49.html 2005-03-21 daily 0.8 http://duduwolf.winzheng.com/post/48.html 2005-03-21 daily 0.8 http://duduwolf.winzheng.com/post/47.html 2005-03-21 daily 0.8 http://duduwolf.winzheng.com/post/45.html 2005-03-19 daily 0.8 http://duduwolf.winzheng.com/post/43.html 2005-03-18 daily 0.8 http://duduwolf.winzheng.com/post/38.html 2005-03-17 daily 0.8 http://duduwolf.winzheng.com/post/42.html 2005-03-17 daily 0.8 http://duduwolf.winzheng.com/post/41.html 2005-03-16 daily 0.8 http://duduwolf.winzheng.com/post/40.html 2005-03-16 daily 0.8 http://duduwolf.winzheng.com/post/39.html 2005-03-16 daily 0.8 http://duduwolf.winzheng.com/post/37.html 2005-03-13 daily 0.8 http://duduwolf.winzheng.com/post/36.html 2005-03-12 daily 0.8 http://duduwolf.winzheng.com/post/35.html 2005-03-12 daily 0.8 http://duduwolf.winzheng.com/post/34.html 2005-03-10 daily 0.8 http://duduwolf.winzheng.com/post/33.html 2005-03-09 daily 0.8 http://duduwolf.winzheng.com/post/32.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/31.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/30.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/29.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/28.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/27.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/26.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/25.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/24.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/23.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/22.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/21.html 2005-03-07 daily 0.8 http://duduwolf.winzheng.com/post/19.html 2005-03-03 daily 0.8 http://duduwolf.winzheng.com/post/16.html 2005-02-25 daily 0.8 http://duduwolf.winzheng.com/post/15.html 2005-02-24 daily 0.8 http://duduwolf.winzheng.com/post/14.html 2005-02-24 daily 0.8 http://duduwolf.winzheng.com/post/13.html 2005-02-24 daily 0.8 http://duduwolf.winzheng.com/post/12.html 2005-02-24 daily 0.8 http://duduwolf.winzheng.com/post/11.html 2005-02-23 daily 0.8 http://duduwolf.winzheng.com/post/10.html 2005-02-23 daily 0.8 http://duduwolf.winzheng.com/post/9.html 2005-02-23 daily 0.8 http://duduwolf.winzheng.com/post/8.html 2005-02-23 daily 0.8 http://duduwolf.winzheng.com/post/7.html 2005-02-23 daily 0.8 http://duduwolf.winzheng.com/post/6.html 2005-02-23 daily 0.8 http://duduwolf.winzheng.com/post/5.html 2005-02-22 daily 0.8 http://duduwolf.winzheng.com/post/4.html 2005-02-22 daily 0.8 http://duduwolf.winzheng.com/post/3.html 2005-02-22 daily 0.8 http://duduwolf.winzheng.com/post/2.html 2005-02-21 daily 0.8 http://duduwolf.winzheng.com/post/1.html 2005-02-21 daily 0.8 登陆Google提交你的SiteMap文件,让Google开始爬行吧 打开https://www.google.com/webmasters/sitemaps/链接,如果还没有注册或者登陆Google,就先用自己的帐号登陆Google,登陆后转到Your Sitemaps状态页面,可以点击那个Add a Sitemap + 跳转到提交页面进行Sitemap文件的提交。建议文件放在你的站点根目录下。给Google提交你的Sitemap URL后可以看见在列表里已存在,不过这时候还没有生效,必须过几个小时后Status栏变成OK表示正式生效,如果不是OK,可以查看Google给出的状态标示解释看看是什么原因。 UPDATE:打包下载z-blog和Wordpress系统的Sitemap生成小工具 build_google_sitemap_tools.zip UPDATE II:从webleon得到最新消息,Google也支持普通的Rss Feed,所以你也可以直接把你的Rss Url提交给Google也能达到同样效果