jisilva233/scanner-imob-portais
GitHub: jisilva233/scanner-imob-portais
面向巴西主流房产门户网站的自动化房源采集与分析工具,支持多平台并行抓取、MD5去重和交互式筛选面板。
Stars: 0 | Forks: 0
# 🏠 Scanner Imob Portais
针对 **Zap Imóveis**、**VivaReal** 和 **OLX** 房产门户网站的自动化房源广告扫描器,使用 PostgreSQL 存储并通过 Streamlit 提供分析面板。
## 功能特性
- 通过 Playwright 同时从 3 个门户网站自动采集房源广告
- 使用 PostgreSQL 存储,并通过 MD5 指纹进行去重
- 简单的 CLI 脚本:`python scan_listings.py --city "São Paulo"`
- 具备价格、街区(bairro)和面积筛选功能的交互式 Web 面板
## 前置条件
- Python 3.10+
- PostgreSQL 13+
- [Playwright](https://playwright.dev/python/) 及 Chromium
## 安装
```
# 1. 克隆仓库
git clone https://github.com/jisilva233/scanner-imob-portais.git
cd scanner-imob-portais
# 2. 创建并激活虚拟环境
python -m venv .venv
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
# 3. 安装依赖
pip install -r requirements.txt
# 4. 安装 Playwright 浏览器
playwright install chromium
# 5. 配置环境变量
cp .env.example .env
# 编辑 .env 并填入您的 DATABASE_URL
```
## 配置
编辑 `.env` 文件:
```
DATABASE_URL=postgresql://usuario:senha@localhost:5432/imob_scraper
```
创建数据库和数据表:
```
python -c "from db.migrations import run_migrations; run_migrations()"
```
## 使用方法
### 采集房源广告
```
# 默认城市 — 每个 portal 最多 10 页
python scan_listings.py --city "São Paulo"
# 限制页面(用于测试更快)
python scan_listings.py --city "Curitiba" --max-pages 3
```
预期输出:
```
🏠 Iniciando scan para: São Paulo (max 10 páginas por portal)
==================================================
Zap Imóveis : 124 anúncios
VivaReal : 98 anúncios
OLX : 67 anúncios
──────────────────────────────
Total coletado : 289
Inseridos : 274
Duplicados : 15
Erros : 0
==================================================
```
### 打开面板
```
streamlit run dashboard/app.py
```
访问:[http://localhost:8501](http://localhost:8501)
**可用筛选器:**
- 价格 (R$) — 区间滑块
- 街区 (Bairro) — 多选
- 面积 (m²) — 区间滑块
- 门户网站 — ZAP / VIVAREAL / OLX
## 项目结构
```
scanner-imob-portais/
├── scrapers/
│ ├── base.py # Classe abstrata BaseScraper
│ ├── zap_scraper.py # Scraper do Zap Imóveis
│ ├── vivareal_scraper.py # Scraper do VivaReal
│ └── olx_scraper.py # Scraper da OLX
├── db/
│ ├── models.py # Modelo SQLAlchemy + store_listings()
│ └── migrations.py # Criação de tabelas
├── dashboard/
│ └── app.py # Painel Streamlit
├── tests/
│ ├── test_models.py # Testes da camada de dados
│ └── test_scrapers.py # Testes dos scrapers (mock Playwright)
├── scan_listings.py # Entry point CLI
├── requirements.txt
└── .env.example
```
## 测试
```
python -m pytest tests/ -v
```
31 个单元测试覆盖:
- 价格、面积和房间数的解析
- MD5 指纹生成
- 相对 URL → 绝对 URL 转换
- 卡片提取 (Playwright mock)
- 带去重功能的 store_listings()
## 技术栈
| 层级 | 技术 |
|--------|-----------|
| 爬虫 | Playwright (async) |
| ORM | SQLAlchemy 2.0 |
| 数据库 | PostgreSQL |
| 校验 | Pydantic v2 |
| 仪表盘 | Streamlit |
| 测试 | pytest + pytest-asyncio |
## 许可证
MIT
标签:Kubernetes, MD5, OLX, Playwright, PostgreSQL, Python, Streamlit, VivaReal, Web Scraping, ZAP Imoveis, 命令控制, 安全规则引擎, 房产监控, 房地产, 数据去重, 数据采集, 无后门, 测试用例, 浏览器自动化, 特征检测, 网络调试, 自动化, 自定义脚本, 访问控制, 逆向工具