sitemap.xml 示例

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.example.com/</loc>
    <lastmod>2024-06-27</lastmod>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>https://www.example.com/about</loc>
    <lastmod>2024-06-26</lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.8</priority>
  </url>
</urlset>

这个 sitemap.xml 文件包含了两个 URL,分别是网站的主页和关于页面。它们的最后修改时间、更新频率和优先级也被标注出来。

基本概念

child::sitemap索引

暴露sitemap

方案

  • 通过robots.txt指定
  • 放在网站的习惯目录(如sitemap/或根目录)下
    • 等待爬虫爬取

实际应用

  • sitemap可以并不保存在网站目录下,而是使用后端请求服务处理爬虫来访,然后从别的地方拉去sitemap,并返回给爬虫