简单静态网站镜像爬虫。给定 URL 下载整个域名下的 HTML、JS、CSS 和静态资源到本地,支持离线浏览。
纯 Python3 标准库,无额外依赖
TinyScraper/
├── SKILL.md
├── bin/
│ └── tinyscraper # CLI 入口
├── lib/
│ └── crawler.py # 核心爬虫逻辑
├── conf/
│ └── .tinyscraper.conf # 配置文件
├── assets/
├── scripts/
│ └── test_crawler.py # 自动化测试
└── references/
└── SPEC.md # 格式标准文档
将目标网站完整镜像到本地,包括:
--dry-run 预览爬取范围tinyscraper "https://example.com"
tmp/mirrors/{domain}/index.html 离线浏览# 完整镜像
tinyscraper "https://example.com"
# 预览模式(只列出 URL,不下载)
tinyscraper "https://example.com" --dry-run
# 清理已下载的镜像
tinyscraper -d example.com
# 显示帮助
tinyscraper -h
tmp/mirrors/{domain}/
├── index.html
├── page/
│ └── index.html
├── assets/
│ ├── style.css
│ └── script.js
├── images/
│ └── logo.png
| URL | 本地路径 |
|---|---|
/ | index.html |
/about | about/index.html |
/page?id=1 | page/index.html |
/style.css?v=1.2 | style.css(去重) |
/page#section | # 锚点去除,视为同一文件 |
href/src → 相对路径url() → 相对路径mailto:/tel:/javascript: → 保留原值不处理[STEP] 🌐 开始镜像: https://example.com
[STEP] 📁 保存目录: tmp/mirrors/example.com
[INFO] 保存页面: https://example.com -> .../index.html
[INFO] 保存资源: https://example.com/style.css -> .../style.css
[STEP] 爬取 (1): https://example.com/about
[INFO] 进度: 已爬 3 页面, 12 资源, 5 待爬
...
[INFO] ==================================================
[INFO] 镜像完成!
[INFO] 页面: 15
[INFO] 资源: 48
[INFO] 失败: 2
[INFO] 目录: tmp/mirrors/example.com
仅支持简单静态网站(SPA/React/Vue 等 JS 驱动类不适用)
外部域名资源(如 CDN 上的 JS)不会下载
需目标网站允许爬取(robots.txt 规则被忽略)