feat(library): add vocation filter, normalize categories, improve grid layout
Added vocation state and included it in query string builder, updated onFilter to accept a vocation parameter, improved grid layout with grid flow classes, normalized category names for consistent item icons, and refined stats mapping to handle type safety.
This commit is contained in:
1 parent
44d7f8ce81
commit
2b790d8eb4
19 files changed
+2638
-173
No files matched your search
@@ -0,0 +1,292 @@
|
||||
# 🎯 Configuração de Filtros de Tabelas
|
||||
|
||||
## Visão Geral
|
||||
|
||||
O scraper foi configurado para usar um sistema de priorização e filtragem de tabelas para garantir que apenas os dados corretos sejam extraídos do TibiaWiki.
|
||||
|
||||
## 📊 Sistema de Priorização
|
||||
|
||||
### Prioridade 1: Tabela com ID "tabelaDPL"
|
||||
|
||||
**Prioridade MÁXIMA**: Se existir uma tabela com `id="tabelaDPL"`, ela será usada exclusivamente.
|
||||
|
||||
```html
|
||||
<table id="tabelaDPL">
|
||||
<!-- Esta tabela será processada -->
|
||||
</table>
|
||||
```
|
||||
|
||||
**Comportamento:**
|
||||
- ✅ Tabela com ID `tabelaDPL` é sempre priorizada
|
||||
- ✅ Se encontrada, outras tabelas são ignoradas
|
||||
- ✅ Log informa: "Tabela com ID 'tabelaDPL' encontrada (prioridade máxima)"
|
||||
|
||||
---
|
||||
|
||||
### Prioridade 2: Tabelas com Classe "wikitable"
|
||||
|
||||
**Fallback 1**: Se não houver tabela com ID `tabelaDPL`, procura por tabelas com classe `wikitable`.
|
||||
|
||||
```html
|
||||
<table class="wikitable">
|
||||
<!-- Esta tabela será processada se não houver ID tabelaDPL -->
|
||||
</table>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Prioridade 3: Todas as Tabelas
|
||||
|
||||
**Fallback 2**: Se não houver nenhuma das anteriores, processa todas as tabelas encontradas na página.
|
||||
|
||||
```html
|
||||
<table>
|
||||
<!-- Esta tabela será processada apenas se não houver ID ou classe -->
|
||||
</table>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚫 Filtro de Exclusão
|
||||
|
||||
### Tabelas Ignoradas: Classe "tibia_client_background_light"
|
||||
|
||||
**SEMPRE IGNORADAS**: Qualquer tabela com a classe `tibia_client_background_light` será ignorada, independente da prioridade.
|
||||
|
||||
```html
|
||||
<table class="tibia_client_background_light">
|
||||
<!-- Esta tabela é IGNORADA, não importa se tem ID tabelaDPL -->
|
||||
</table>
|
||||
|
||||
<table class="wikitable tibia_client_background_light">
|
||||
<!-- Esta tabela também é IGNORADA -->
|
||||
</table>
|
||||
```
|
||||
|
||||
**Comportamento:**
|
||||
- ❌ Tabelas com `tibia_client_background_light` nunca são processadas
|
||||
- 📊 Contador mostra quantas tabelas foram ignoradas
|
||||
- 🔍 Log informa: "Tabelas ignoradas (classe tibia_client_background_light): X"
|
||||
|
||||
---
|
||||
|
||||
## 🔄 Fluxo de Decisão
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────┐
|
||||
│ Buscar tabelas na página │
|
||||
└─────────────┬───────────────────────────┘
|
||||
↓
|
||||
┌─────────────────────────┐
|
||||
│ Existe tabela com │
|
||||
│ ID="tabelaDPL"? │
|
||||
└───┬─────────┬───────────┘
|
||||
│ SIM │ NÃO
|
||||
↓ ↓
|
||||
Usar só ┌───────────────────┐
|
||||
esta tabela│ Existe tabela com │
|
||||
│ class="wikitable"?│
|
||||
└───┬─────────┬─────┘
|
||||
│ SIM │ NÃO
|
||||
↓ ↓
|
||||
Usar só Usar todas
|
||||
estas as tabelas
|
||||
tabelas
|
||||
│
|
||||
↓
|
||||
┌───────────────────────────┐
|
||||
│ Filtrar tabelas com │
|
||||
│ classe "tibia_client_ │
|
||||
│ background_light" │
|
||||
└────────────┬──────────────┘
|
||||
↓
|
||||
┌────────────────┐
|
||||
│ Processar │
|
||||
│ tabelas válidas│
|
||||
└────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📝 Logs e Monitoramento
|
||||
|
||||
### Exemplos de Logs
|
||||
|
||||
**Cenário 1: Tabela com ID encontrada**
|
||||
```
|
||||
INFO: Tabela com ID 'tabelaDPL' encontrada (prioridade máxima)
|
||||
INFO: Total de tabelas encontradas antes da filtragem: 1
|
||||
INFO: Total de tabelas válidas após filtragem: 1
|
||||
INFO: Processando tabela 1/1
|
||||
```
|
||||
|
||||
**Cenário 2: Tabelas com classe ignorada**
|
||||
```
|
||||
INFO: Total de tabelas encontradas antes da filtragem: 5
|
||||
INFO: Tabelas ignoradas (classe tibia_client_background_light): 3
|
||||
INFO: Total de tabelas válidas após filtragem: 2
|
||||
INFO: Processando tabela 1/2
|
||||
```
|
||||
|
||||
**Cenário 3: Nenhuma tabela válida**
|
||||
```
|
||||
WARNING: Tabelas ignoradas (classe tibia_client_background_light): 2
|
||||
WARNING: Nenhuma tabela válida encontrada após filtragem em Espadas
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Casos de Uso
|
||||
|
||||
### Caso 1: Página com ID tabelaDPL
|
||||
|
||||
```html
|
||||
<table id="tabelaDPL">
|
||||
<!-- Itens principais aqui -->
|
||||
</table>
|
||||
|
||||
<table class="wikitable">
|
||||
<!-- Ignorado -->
|
||||
</table>
|
||||
```
|
||||
|
||||
**Resultado:** Apenas tabela `tabelaDPL` é processada.
|
||||
|
||||
---
|
||||
|
||||
### Caso 2: Página com tabelas de layout
|
||||
|
||||
```html
|
||||
<table class="tibia_client_background_light">
|
||||
<!-- Layout/background, ignorado -->
|
||||
</table>
|
||||
|
||||
<table class="wikitable">
|
||||
<!-- Itens aqui, processado -->
|
||||
</table>
|
||||
```
|
||||
|
||||
**Resultado:** Tabela de layout ignorada, tabela `wikitable` processada.
|
||||
|
||||
---
|
||||
|
||||
### Caso 3: Página mista
|
||||
|
||||
```html
|
||||
<table id="tabelaDPL" class="wikitable">
|
||||
<!-- Processado (ID tem prioridade) -->
|
||||
</table>
|
||||
|
||||
<table class="wikitable tibia_client_background_light">
|
||||
<!-- Ignorado (classe filtrada) -->
|
||||
</table>
|
||||
|
||||
<table class="wikitable">
|
||||
<!-- Ignorado (ID tabelaDPL foi encontrada) -->
|
||||
</table>
|
||||
```
|
||||
|
||||
**Resultado:** Apenas a primeira tabela é processada.
|
||||
|
||||
---
|
||||
|
||||
### Caso 4: Página com múltiplas classes
|
||||
|
||||
```html
|
||||
<table class="wikitable">
|
||||
<!-- Processado -->
|
||||
</table>
|
||||
|
||||
<table class="wikitable tibia_client_background_light other-class">
|
||||
<!-- Ignorado (tem classe tibia_client_background_light) -->
|
||||
</table>
|
||||
|
||||
<table class="other-table-class">
|
||||
<!-- Processado (se não houve ID ou wikitable antes) -->
|
||||
</table>
|
||||
```
|
||||
|
||||
**Resultado:** Tabelas com `tibia_client_background_light` sempre ignoradas.
|
||||
|
||||
---
|
||||
|
||||
## 🔍 Debug e Troubleshooting
|
||||
|
||||
### Verificar tabelas encontradas
|
||||
|
||||
Para depurar, adicione prints temporários no código:
|
||||
|
||||
```python
|
||||
# No método scrape_category, após linha 270
|
||||
for idx, table in enumerate(tables):
|
||||
print(f"Tabela {idx+1}: ID={table.get('id')}, Classes={table.get('class')}")
|
||||
```
|
||||
|
||||
### Verificar filtragem
|
||||
|
||||
O log já mostra informações detalhadas:
|
||||
|
||||
```
|
||||
INFO: Total de tabelas encontradas antes da filtragem: 5
|
||||
INFO: Tabelas ignoradas (classe tibia_client_background_light): 2
|
||||
INFO: Total de tabelas válidas após filtragem: 3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚙️ Configuração Técnica
|
||||
|
||||
### Código Implementado
|
||||
|
||||
```python
|
||||
# Prioridade 1: ID tabelaDPL
|
||||
tables = soup.find_all('table', id='tabelaDPL')
|
||||
|
||||
if not tables:
|
||||
# Prioridade 2: Classe wikitable
|
||||
tables = soup.find_all('table', class_='wikitable')
|
||||
|
||||
if not tables:
|
||||
# Prioridade 3: Todas as tabelas
|
||||
tables = soup.find_all('table')
|
||||
|
||||
# Filtro: Remover tibia_client_background_light
|
||||
filtered_tables = []
|
||||
for table in tables:
|
||||
if table.get('class') and 'tibia_client_background_light' in table.get('class'):
|
||||
continue # Ignorar
|
||||
filtered_tables.append(table)
|
||||
|
||||
tables = filtered_tables
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✅ Garantias
|
||||
|
||||
1. **Prioridade absoluta**: ID `tabelaDPL` sempre vence
|
||||
2. **Filtro robusto**: `tibia_client_background_light` sempre ignorado
|
||||
3. **Logs informativos**: Você sabe exatamente o que está acontecendo
|
||||
4. **Fallback seguro**: Se nada funcionar, usa todas as tabelas
|
||||
5. **Performance**: Filtragem rápida sem impacto significativo
|
||||
|
||||
---
|
||||
|
||||
## 📚 Referências
|
||||
|
||||
- **Arquivo modificado**: `iconScript/tibiawiki/spiders/selenium_spider.py`
|
||||
- **Método**: `scrape_category()` (linhas 239-400)
|
||||
- **Dependências**: BeautifulSoup4
|
||||
|
||||
---
|
||||
|
||||
## 🎉 Resultado Final
|
||||
|
||||
Com essas configurações, o scraper:
|
||||
|
||||
✅ Prioriza tabelas com dados reais (ID tabelaDPL)
|
||||
✅ Ignora tabelas de layout/decorativas
|
||||
✅ Fornece logs detalhados para debugging
|
||||
✅ Funciona de forma robusta mesmo com HTML variado
|
||||
✅ Garante que apenas itens corretos sejam extraídos
|
||||
|
||||
Reference in new issue
Block a user