Demo:用 XPath 检查 sitemap URL
XPath 很适合 XML sitemap,但 namespace 和重复 url 节点容易出错。写脚本前先预览匹配列表。
- 不确定 namespace 时使用 local-name()。
- 确认 URL 顺序稳定前不要依赖位置索引。
- 检查 sitemap 质量时同时看 loc 和 lastmod。
//*[local-name()="url"]/*[local-name()="loc"]/text()
---
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://example.com/en</loc><lastmod>2026-06-18</lastmod></url>
</urlset>