sitemap 帮搜索引擎发现你希望展示的规范 URL。文件存在、页面具备可索引条件、已经被搜索引擎收录,是三种不同结论。下面在教学数据上走完“地图与页面双向核对”。
先给完整输入,不靠 HTML 文件总数猜
保存为 sitemap.xml;example.test 是教学域名,不执行线上提交。
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://example.test/a.html</loc></url>
<url><loc>https://example.test/old.html</loc></url>
<url><loc>https://example.test/hidden.html</loc></url>
<url><loc>https://example.test/copy.html</loc></url>
<url><loc>https://example.test/a.html</loc></url>
</urlset>
保存为 page-state.json。下面状态是假设已提供的教学观察,不是真实 HTTP 探测结果;日期为空表示没有可靠的正文变更时间。
[
{"url":"https://example.test/a.html","status":200,"canonical":"https://example.test/a.html","metaRobots":"index,follow","xRobotsTag":"","crawlAllowed":true,"published":true,"lastContentChange":null},
{"url":"https://example.test/b.html","status":200,"canonical":"https://example.test/b.html","metaRobots":"index,follow","xRobotsTag":"","crawlAllowed":true,"published":true,"lastContentChange":null},
{"url":"https://example.test/old.html","status":301,"location":"https://example.test/a.html","canonical":null,"metaRobots":"","xRobotsTag":"","crawlAllowed":true,"published":true,"lastContentChange":null},
{"url":"https://example.test/hidden.html","status":200,"canonical":"https://example.test/hidden.html","metaRobots":"noindex,follow","xRobotsTag":"","crawlAllowed":true,"published":true,"lastContentChange":null},
{"url":"https://example.test/copy.html","status":200,"canonical":"https://example.test/a.html","metaRobots":"index,follow","xRobotsTag":"","crawlAllowed":true,"published":true,"lastContentChange":null}
]
本例站点策略明确只收录已发布、返回 200、允许索引、允许抓取且 canonical 指向自己的主页面。canonical 是规范化信号,不保证搜索引擎一定选中;这里是在检查本站自己的提交口径是否一致。
交给 Codex 的解析与对账任务
只读 sitemap.xml 与 page-state.json。用 XML 解析器解析命名空间,不用正则拆 XML。
验证 XML 可解析、loc 为允许域名的绝对 HTTPS URL、重复 URL、缺失页面状态。
按本文站点策略计算 eligible 集合,分别输出:
duplicates;inMapButIneligible(附具体原因);eligibleButMissing。
输出 audit.json 与 corrected-sitemap.xml,不覆盖原地图,不改变页面 robots/canonical/URL。
页面状态资料是教学输入,不冒充本次 HTTP 请求。没有修改时间就不生成 lastmod。
实际执行命令和退出码写入记录,XML 写入后再次解析,不能只检查字符串有 urlset。
如果项目没有 XML 库,先让 Codex检查现有依赖,再选合适解析器;不能在没有安装或运行的情况下伪造扫描报告。
应得到的双向差异
| 类别 | URL | 原因 |
|---|---|---|
| duplicate | a.html | 地图重复出现两次 |
| ineligible | old.html | 301 跳转,规范承接是 a.html |
| ineligible | hidden.html | 明确 noindex |
| ineligible | copy.html | canonical 指向 a.html |
| missing | b.html | 符合教学站策略但未在地图 |
原地图 5 个 loc、4 个唯一 URL。去掉一个重复项、三个不合资格的唯一项,再加入 b,修正后应有 2 个唯一 URL:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://example.test/a.html</loc></url>
<url><loc>https://example.test/b.html</loc></url>
</urlset>
不能为了让 hidden.html 留在 sitemap,就顺手移除它的 noindex;页面索引政策可能有明确业务原因。目录页也不因“正文较短”自动排除,应按目录职责与站点既定策略判断。
从教学输入换成真实站点时,还差哪些证据
本地 HTML 能提取 meta robots 和 canonical,却无法证明当前服务器状态、X-Robots-Tag、重写、重定向链与 robots.txt。上线前后应分开记录 URL、时间、HTTP 状态、最终地址、响应头和页面字段,缺少线上权限时保留待查。
robots.txt 控制抓取,不能等同 noindex;被禁止抓取的页面可能无法让 Google 看到页面里的 noindex。Google 的 noindex 说明明确区分了这两层。
lastmod 应来自可靠的正文或其他重要内容变化时间,不能每次构建全刷当天。地图应列希望展示的 canonical URL;参见官方 sitemap 规范。没有日期来源时,本例省略可选 lastmod。
真实收录状态需要 Search Console 等授权平台的页面级证据。地图解析通过、URL 返回 200 或搜索 site: 没找到,都不足以自行填写“已收录/确定未收录”。本练习只完成地图修正建议,不部署、不提交。
下一步
继续阅读与你当前问题相关的教程:


