Google sitemaps perl程序

时间:2007-02-24 17:01:18   来源:groups.google.com  作者:  点击:次  出处:技术无忧
关键字:Google sitemaps perl

I've written the following - haven't yet seen Google approve of it's
output so it could have a bug, but still may be a place to start:

If it prints anything on the screen you have a potentially bad filename
and you'll need to add encoding code for it.. or skip it, or remove
it..


#!/usr/bin/perl
my $sitepath="/yourhtdocs";
my $website="http://yoursite.com";


chdir($sitepath);
@stuff=`find . -type f -name "*.html"`;
open(O,">sitemap");
print O <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
EOF
foreach (@stuff) {
 chomp;
 $badone=$_;
 $badone =~ tr/-_.\/a-zA-Z0-9//cd;
 print if ($badone ne $_);
 s/^..//;
$rfile="$sitepath/$_";
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize­,$blocks)=stat
$rfile;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($mtime);
$year +=1900;
$mon++;
$mod=sprintf("%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d+00:00",$year,$mon,$mday,$­hour,$min,$sec);
$mod=sprintf("%0.4d-%0.2d-%0.2d",$year,$mon,$mday);
$freq="monthly";
$freq="daily" if /index.html/;
$priority="0.5";
$priority="0.7" if /index.html/;
$priority="0.9" if /\/index.html/;


print O <<EOF;
<url>
      <loc>$website/$_</loc>
      <lastmod>$mod</lastmod>
      <changefreq>$freq</changefreq>
      <priority>$priority</priority>
</url>
EOF


}


print O <<EOF;
</urlset>
EOF
close O;
unlink("sitemap.gz");
system("gzip sitemap");

有关操作系统的更多文章请进:技术无忧


文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面