从 https://mikrotik.com/hardware 自动抓取全量硬件产品,生成可检索的静态网站与 JSON API。
在线地址: https://mt.hex.ac.cn
product_url 去重,重复产品执行 UPSERT 而非重复插入images/ 目录index.html(基于 template.html 模板)api.json,供前端或其他服务调用| 文件 | 说明 |
|---|---|
crawler.py | 爬虫主程序,抓取产品数据并写入 SQLite |
generate_site.py | 从数据库读取数据,生成 HTML + JSON |
template.html | 前端模板(含搜索、筛选、对比、分页等交互) |
index.html | 生成的静态页面 |
api.json | 生成的 JSON API 数据 |
mikrotik_products.db | SQLite 数据库 |
images/ | 产品图片目录 |
run.sh | 本地一键运行脚本(抓取 + 生成 + 启动预览服务器) |
.cnb.yml | CNB CI/CD 流水线配置(每 3 小时定时构建 + 部署到 EdgeOne Pages) |
python3 -m pip install --break-system-packages -r requirements.txt
核心依赖:requests、beautifulsoup4
bash run.sh
自动完成:安装依赖 → 抓取数据 → 生成站点 → 启动 HTTP 预览服务
python3 crawler.py --db mikrotik_products.db --images-dir images
说明:
mikrotik_products.dbimages/product_url 去重并更新字段python3 generate_site.py --db mikrotik_products.db --out index.html
可选参数:
--template template.html — 指定 HTML 模板文件(默认 template.html)--json api — 指定 JSON API 输出路径前缀(默认 api,生成 api.json)表格列包含:
{
"code": 200,
"message": "success",
"data": {
"total": 600,
"products": [ { ... } ]
},
"metadata": {
"source": "MikroTik 官网",
"update_time": "2025-01-15 08:00",
"generated_by": "mt.hex.ac.cn"
}
}
| 表名 | 说明 |
|---|---|
products | 产品聚合信息(名称、型号、图片、CPU、价格、性能摘要、状态等) |
categories | 分类字典(name + slug) |
product_categories | 产品与分类多对多关系 |
specifications | 规格明细(section / key / value) |
test_results | 测试结果明细(metrics_json 以 JSON 存储各包大小下的 kpps/Mbps) |
项目通过 CNB 平台实现自动化流水线(.cnb.yml):
0 */3 * * *)mt-hex-ac-cn(EdgeOne Pages production 环境)