google sitemap用 sitemap.xmlの作成
sorry Japanese only
PAGE作成日 2005/11/26
最終更新日 2006/08/19
page size = Mbyte

googleに新しく sitemapという機能が始まりました。
自分のサイトを登録しておくと、クローラーのエラー状況とかが確認できるらしいです。
これはおもしろそうだ?と思い登録しようとしましたが、sitemap.xmlというファイルを用意しておかなければならないとのこと。

以下は google sitemapにて用いる sitemap.xmlを自宅サーバーではどうやって作成するか?の方法です。

情報漏洩に関する注意事項

公開している、公開していないに関係無く、指定したディレクトリー以下のファイル一覧が sitemap.xmlに書き出されます。
一時期、会社の存続にも影響するような hpからの情報ダダ漏れ事件、directory Options Indexesか、それ以上の情報ダダ漏れに発展する可能性を秘めています。

公開する内容、許可しない設定を良く考慮してから sitemap.xmlを公開するようにしましょう。

google-sitemap_genの Download

SourceForge.netより google-sitemap_genを Downloadしてきます

以下のファイルが入っています。
[root]# tar ztvf sitemap_gen-1.3.tar.gz
drwxr-xr-x opensource/opensource 0 2005-09-08 06:44:40 sitemap_gen-1.3/
-r--r----- opensource/opensource 22 2005-06-17 04:41:30 sitemap_gen-1.3/AUTHORS
-r--r----- opensource/opensource 1754 2005-06-17 04:41:30 sitemap_gen-1.3/COPYING
-r--r--r-- opensource/opensource 2003 2005-09-08 06:35:41 sitemap_gen-1.3/ChangeLog
-r--r--r-- opensource/opensource 1094 2005-09-08 06:35:41 sitemap_gen-1.3/README
-r--r--r-- opensource/opensource 5498 2005-09-08 06:35:41 sitemap_gen-1.3/example_config.xml
-r--r----- opensource/opensource  975 2005-06-17 04:41:30 sitemap_gen-1.3/example_urllist.txt
-r-xr-xr-x opensource/opensource 70647 2005-09-08 06:35:41 sitemap_gen-1.3/sitemap_gen.py
-r-xr-xr-x opensource/opensource 27786 2005-09-08 06:35:41 sitemap_gen-1.3/test_sitemap_gen.py
-r-xr-xr-x opensource/opensource   305 2005-09-08 06:35:41 sitemap_gen-1.3/setup.py
-rw-r--r-- opensource/opensource   248 2005-09-08 06:44:40 sitemap_gen-1.3/PKG-INFO

上記ファイルを /usr/localとかに向けて解凍します。

config.xmlファイルの作成

example_config.xmlを参考にして、自分のサイトに合わせた config.xmlファイルを作成します。
このサイト http://legacy-b4.dyndns.org/ 用の config.xmlファイルは以下の物です。
<?xml version="1.0" encoding="UTF-8"?>
<site
  base_url="http://legacy-b4.dyndns.org/"
  store_into="/home/localhost/legacy-b4/sitemap.xml"
  verbose="1"
  default_encoding="EUC-JP"
  >

  <directory
     path="/home/localhost/legacy-b4/"
     url="http://legacy-b4.dyndns.org/"
     default_file="index.html"
  />

  <filter  action="drop"  type="wildcard"  pattern="*/wp/*" />
</site>

自宅サーバー apacheの設定で denyにしているようなディレクトリーも、お構いなしに sitemap.xml上に反映されてしまいます。
公開したくないディレクトリーは、くれぐれも忘れずに dropの指定をしましょう。


これを実行して作成された sitemap.xmlはこちら => sitemap.xml

google sitemapの結果

google sitemapの新規登録画面から sitemap.xmlを登録すると、以下のようなログが apacheの access.logに残ります。
crawl-66-249-65-199.googlebot.com - - [26/Nov/2005:13:40:56 +0900] "HEAD /sitemap.xml HTTP/1.1" 200 - 283 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
crawl-66-249-65-199.googlebot.com - - [26/Nov/2005:14:01:56 +0900] "GET /sitemap.xml HTTP/1.1" 200 285995 286278 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

その後、自分のサイトであるのを確認するための verification fileと言うのを hpへ uploadします。
今回指定されたのは GOOGLE3fc61528ca0xxxxx.htmlと言うのを / へ置けとのことでした。
この暗号のようなファイルを uploadしたところ、以下のような情報が見れるようになりました。
google sitemap

苦労した割には大したことがないような。

この sitemap.xmlを定期的に作成すると良いようなことも書いてありますが、
定期的に作成して意味があるのでしょうか。
まあ 1日 1回 cronで動かしてみることにします。

エラーが出たとき

サーバーを入れ替えたら以下のエラーが出てスクリプトが動作しなくなってしまいました
[root]# python sitemap_gen.py --config=config2.xml
Reading configuration file: config2.xml
Walking DIRECTORY "/home/localhost/legacy-b4/"
Sorting and normalizing collected URLs.
Writing Sitemap file "sitemap.xml" with 702 URLs
Notifying search engines.
[ERROR] When attempting to access our generated Sitemap at the following URL:
    http://legacy-b4.dyndns.org/sitemap.xml
  we failed to read it.  Please verify the store_into path you specified in
  your configuration file is web-accessable.  Consult the FAQ for more
  information.
[WARNING] Proceeding to notify with an unverifyable URL.
Notifying: www.google.com
Count of file extensions on URLs:
     134  .gif
       1  .gz
      82  .html
       1  .ico
     352  .jpg
       1  .lzh
      59  .png
      15  .txt
      57  /
Number of errors: 1
Number of warnings: 1
Notifying search engines.で止まってしまい、長い時間かかった後 [ERROR]が表示されます
最初は何でか気が付かなかったのですが、googleが私のサイトを見れないのではなく
pythonが legacy-b4.dyndns.orgにたどり着けなかったのです。

/etc/hostへ入れ忘れていました
192.168.24.5  legacy-b4.dyndns.org


参考にさせていただいたサイト ぐーぐる さいとまっぷす へるぷ さん

9144
戻る