3

我有一个包含 100 多个 html 文件的目录的网站。我希望爬虫爬取该目录的所有 html 文件。我已经在我的 robots.txt 中添加了以下句子:

Allow /DirName/*.html$

有什么方法可以将目录中的文件包含在 sitemap.xml 文件中,以便抓取目录中的所有 html 文件?像这样的东西:

<url>
    <loc>MyWebsiteName/DirName/*.html</loc>
</url>
4

2 回答 2

1

站点地图协议既不限制也不允许使用通配符;老实说,这是我第一次听到这个。另外,我很确定搜索引擎不能在站点地图中使用通配符。

请查看 Google 对站点地图生成器的推荐。眨眼之间,您可以使用大量工具创建站点地图。

于 2010-07-31T18:07:58.707 回答
0

它不允许使用通配符。如果您在服务器中运行 php,那么您可以列出目录中的所有文件并使用DirectoryIterator自动生成 sitemap.xml 。

// this is assume you have already a sitemap class.
$sitemap = new Sitemap;

// iterate the directory
foreach(new DirectoryIterator('/MyWebsiteName/DirName') as $directoryItem)
{
    // Filter the item
    if(!$directoryItem->isFile()) continue;

    // New basic sitemap.
    $url = new Sitemap_URL;

    // Set arguments.
    $url->set_loc(sprintf('/DirName/%1$s', $directoryItem->getBasename()))
        ->set_last_mod(1276800492)
        ->set_change_frequency('daily')
        ->set_priority(1);

    // Add it to sitemap.
    $sitemap->add($url);
}

// Render the output.
$response = $sitemap->render();

// Cache the output for 24 hours.
$cache->set('sitemap', $response, 86400);

// Output the sitemap.
echo $response;
于 2015-04-06T08:07:13.483 回答