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.
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
"""
|
|
Script de teste rápido para verificar se o Selenium spider funciona
|
|
"""
|
|
import sys
|
|
import os
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from tibiawiki.spiders.selenium_spider import SeleniumSpider
|
|
|
|
|
|
def main():
|
|
"""
|
|
Testa o spider apenas com uma categoria (Capacetes)
|
|
"""
|
|
print("=" * 80)
|
|
print("TESTE RÁPIDO - Selenium Spider")
|
|
print("=" * 80)
|
|
print("\nEste teste processa apenas a categoria 'Capacetes'.")
|
|
print("O navegador Chrome será aberto.\n")
|
|
|
|
# Cria spider
|
|
spider = SeleniumSpider(
|
|
db_path='data/tibiawiki_test.db',
|
|
images_path='data/images_test',
|
|
headless=False
|
|
)
|
|
|
|
try:
|
|
# Setup
|
|
spider.setup_driver()
|
|
spider.setup_database()
|
|
|
|
# Testa apenas Capacetes
|
|
url = "https://www.tibiawiki.com.br/wiki/Capacetes"
|
|
spider.scrape_category("Capacetes", url)
|
|
|
|
print(f"\n{'='*80}")
|
|
print(f"Teste concluído!")
|
|
print(f"Total de itens extraídos: {spider.items_scraped}")
|
|
print(f"{'='*80}")
|
|
|
|
# Verifica dados
|
|
print("\nVerificando banco de dados...")
|
|
spider.cursor.execute("SELECT COUNT(*) FROM capacetes")
|
|
count = spider.cursor.fetchone()[0]
|
|
print(f"Capacetes salvos no banco: {count}")
|
|
|
|
# Mostra alguns exemplos
|
|
spider.cursor.execute("SELECT nome, nivel, peso FROM capacetes LIMIT 5")
|
|
rows = spider.cursor.fetchall()
|
|
print("\nExemplos de itens extraídos:")
|
|
for row in rows:
|
|
print(f" - {row[0]} (Nível: {row[1]}, Peso: {row[2]} oz)")
|
|
|
|
except Exception as e:
|
|
print(f"\nErro no teste: {e}")
|
|
raise
|
|
|
|
finally:
|
|
spider.close_database()
|
|
spider.close_driver()
|
|
|
|
print("\nTeste finalizado com sucesso!")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|