feat: add TibiaWiki scraper project and update .gitignore
Integrates a Scrapy-based TibiaWiki scraper (spider, pipelines, SQLite/Images settings, README). Updates .gitignore to exclude generated data directories (/iconScript/data, /data/images) to keep the repository clean.
This commit is contained in:
1 parent
bf12f2c6f1
commit
29ba5aece0
27 files changed
+1702
-4
No files matched your search
@@ -0,0 +1,101 @@
|
||||
# Correções Aplicadas - Erro 403 e image_local_path
|
||||
|
||||
## Problemas Identificados
|
||||
|
||||
### 1. Erro 403 Forbidden
|
||||
- **Causa**: Site bloqueando requisições automatizadas do Scrapy
|
||||
- **Solução**: Implementação com Selenium para simular navegador real
|
||||
|
||||
### 2. Erro "no such column: image_local_path"
|
||||
- **Causa**: Campo `image_local_path` não era criado na tabela
|
||||
- **Solução**: Adicionado campo na criação da tabela + tratamento de erro
|
||||
|
||||
## Mudanças no Código
|
||||
|
||||
### arquivo: `tibiawiki/spiders/selenium_spider.py`
|
||||
|
||||
#### Mudança 1: Garantir campos de imagem na tabela
|
||||
```python
|
||||
# ANTES
|
||||
columns_def = []
|
||||
for field_name, field_value in item_data.items():
|
||||
sql_type = ...
|
||||
columns_def.append(f"{field_name} {sql_type}{constraint}")
|
||||
|
||||
# DEPOIS
|
||||
columns_def = []
|
||||
added_fields = set()
|
||||
|
||||
for field_name, field_value in item_data.items():
|
||||
...
|
||||
added_fields.add(field_name)
|
||||
|
||||
# Sempre adiciona campos de imagem
|
||||
if 'image_url' not in added_fields:
|
||||
columns_def.append("image_url TEXT")
|
||||
if 'image_local_path' not in added_fields:
|
||||
columns_def.append("image_local_path TEXT")
|
||||
```
|
||||
|
||||
#### Mudança 2: Tratamento de erro ao atualizar image_local_path
|
||||
```python
|
||||
# Adicionado tratamento para quando coluna não existe
|
||||
try:
|
||||
self.cursor.execute(
|
||||
f"UPDATE {table_name} SET image_local_path=? WHERE nome=?",
|
||||
(file_path, item_data.get('nome'))
|
||||
)
|
||||
except sqlite3.OperationalError as e:
|
||||
if 'no such column' in str(e):
|
||||
# Adiciona coluna se não existir
|
||||
self.cursor.execute(f"ALTER TABLE {table_name} ADD COLUMN image_local_path TEXT")
|
||||
# Tenta atualizar novamente
|
||||
...
|
||||
```
|
||||
|
||||
## Como Testar
|
||||
|
||||
### 1. Teste Rápido (apenas Capacetes)
|
||||
```bash
|
||||
python test_selenium.py
|
||||
```
|
||||
|
||||
### 2. Execução Completa
|
||||
```bash
|
||||
python main_selenium.py
|
||||
```
|
||||
|
||||
## Limpeza de Dados Anteriores
|
||||
|
||||
Se você já executou antes e teve erros, delete o banco antigo:
|
||||
|
||||
```bash
|
||||
# Windows PowerShell
|
||||
Remove-Item -Path data\tibiawiki.db -Force
|
||||
|
||||
# Linux/Mac
|
||||
rm data/tibiawiki.db
|
||||
```
|
||||
|
||||
Depois rode novamente para criar as tabelas com a estrutura correta.
|
||||
|
||||
## Arquivos Modificados
|
||||
|
||||
1. ✅ `tibiawiki/spiders/selenium_spider.py` - Correção dos campos de imagem
|
||||
2. ✅ `requirements.txt` - Adicionado Selenium e webdriver-manager
|
||||
3. ✅ `main_selenium.py` - Script principal com Selenium
|
||||
4. ✅ `test_selenium.py` - Script de teste criado
|
||||
|
||||
## Status
|
||||
|
||||
- ✅ Erro 403 resolvido com Selenium
|
||||
- ✅ Erro image_local_path corrigido
|
||||
- ✅ Backup dos campos de imagem sempre criado
|
||||
- ✅ Tratamento robusto de erros SQL
|
||||
|
||||
## Próximos Passos
|
||||
|
||||
1. Execute o teste: `python test_selenium.py`
|
||||
2. Se funcionar, rode completo: `python main_selenium.py`
|
||||
3. Verifique os dados: `sqlite3 data/tibiawiki.db`
|
||||
|
||||
Reference in new issue
Block a user