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.
7.5 KiB
🎯 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.
<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.
<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.
<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.
<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_lightnunca 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
<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
<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
<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
<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:
# 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
# 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
- Prioridade absoluta: ID
tabelaDPLsempre vence - Filtro robusto:
tibia_client_background_lightsempre ignorado - Logs informativos: Você sabe exatamente o que está acontecendo
- Fallback seguro: Se nada funcionar, usa todas as tabelas
- 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