Sitemap Generator
Crawl any website and produce a standards-compliant XML sitemap ready for search engine submission.
Quick Start
CODEBLOCK0
Output: sitemap.xml in the current directory.
Commands
CODEBLOCK1
Options
| Flag | Default | Description |
|---|
| INLINECODE1 | INLINECODE2 | Output file path (use - for stdout) |
| INLINECODE4 |
200 | Maximum pages to crawl |
|
--max-depth |
5 | Maximum link depth from start URL |
|
--delay |
0.2 | Seconds between requests |
|
--timeout |
10 | Request timeout in seconds |
|
--changefreq |
weekly | Sitemap changefreq hint |
|
--priority |
0.5 | Sitemap priority hint (0.0–1.0) |
|
--verbose, -v | off | Print crawl progress to stderr |
Dependencies
CODEBLOCK2
Notes
- - Only crawls same-domain pages (no external links)
- Skips binary files (images, CSS, JS, PDFs, fonts)
- Respects the delay setting to avoid overwhelming servers
- Output conforms to the sitemaps.org 0.9 protocol
站点地图生成器
抓取任意网站并生成符合标准、可供搜索引擎提交的XML站点地图。
快速开始
bash
python3 scripts/sitemap_gen.py https://example.com
输出:当前目录下的 sitemap.xml 文件。
命令
bash
基础用法 — 抓取并写入 sitemap.xml
python3 scripts/sitemap_gen.py https://example.com
自定义输出路径
python3 scripts/sitemap_gen.py https://example.com -o /tmp/sitemap.xml
限制抓取范围
python3 scripts/sitemap_gen.py https://example.com --max-pages 500 --max-depth 3
礼貌抓取(带延迟)
python3 scripts/sitemap_gen.py https://example.com --delay 1.0
设置SEO提示
python3 scripts/sitemap_gen.py https://example.com --changefreq daily --priority 0.8
显示详细进度
python3 scripts/sitemap_gen.py https://example.com -v
输出到标准输出
python3 scripts/sitemap_gen.py https://example.com -o -
选项
| 标志 | 默认值 | 描述 |
|---|
| --output, -o | sitemap.xml | 输出文件路径(使用 - 表示标准输出) |
| --max-pages |
200 | 最大抓取页面数 |
| --max-depth | 5 | 从起始URL开始的最大链接深度 |
| --delay | 0.2 | 请求间隔秒数 |
| --timeout | 10 | 请求超时秒数 |
| --changefreq | weekly | 站点地图更新频率提示 |
| --priority | 0.5 | 站点地图优先级提示(0.0–1.0) |
| --verbose, -v | 关闭 | 将抓取进度输出到标准错误流 |
依赖
bash
pip install requests beautifulsoup4
说明
- - 仅抓取同域名页面(不包含外部链接)
- 跳过二进制文件(图片、CSS、JS、PDF、字体)
- 遵守延迟设置以避免对服务器造成过大压力
- 输出符合 sitemaps.org 0.9 协议