fix: extracao estrita do nome real da empresa ignorando cabecalho de Resultados do Google Maps
This commit is contained in:
@@ -104,18 +104,26 @@ class ScraperService:
|
||||
detail_panel = page.query_selector("div[role='main']") or page.query_selector("div.m6QEbd")
|
||||
detail_text = detail_panel.inner_text() if detail_panel else card.inner_text()
|
||||
|
||||
# 1. Nome da Empresa (h1 do painel ou aria-label do card)
|
||||
h1_elem = page.query_selector("h1")
|
||||
nome_empresa = ""
|
||||
if h1_elem:
|
||||
nome_empresa = h1_elem.inner_text().strip()
|
||||
if not nome_empresa:
|
||||
# 1. Nome da Empresa (priorizar aria-label do card ou h1 dentro do detail_panel)
|
||||
nome_empresa = (card.get_attribute("aria-label") or "").strip()
|
||||
if not nome_empresa:
|
||||
lines = [l.strip() for l in card.inner_text().split('\n') if l.strip()]
|
||||
nome_empresa = lines[0] if lines else ""
|
||||
if nome_empresa.lower() in ('resultados', 'resultado', ''):
|
||||
nome_empresa = ""
|
||||
|
||||
if not nome_empresa and detail_panel:
|
||||
h1_elem = detail_panel.query_selector("h1")
|
||||
if h1_elem:
|
||||
h_txt = h1_elem.inner_text().strip()
|
||||
if h_txt and h_txt.lower() not in ('resultados', 'resultado'):
|
||||
nome_empresa = h_txt
|
||||
|
||||
if not nome_empresa:
|
||||
lines = [l.strip() for l in card.inner_text().split('\n') if l.strip()]
|
||||
for line in lines:
|
||||
if line and line.lower() not in ('resultados', 'resultado') and not re.search(r'^[1-5][.,]\d', line):
|
||||
nome_empresa = line
|
||||
break
|
||||
|
||||
if not nome_empresa or nome_empresa.lower() in ('resultados', 'resultado'):
|
||||
continue
|
||||
|
||||
# 2. Telefone detalhado
|
||||
@@ -182,10 +190,14 @@ class ScraperService:
|
||||
else:
|
||||
# Se for resultado único direto
|
||||
try:
|
||||
h1_elem = page.query_selector("h1")
|
||||
if h1_elem:
|
||||
nome_empresa = h1_elem.inner_text().strip()
|
||||
detail_panel = page.query_selector("div[role='main']") or page.query_selector("div.m6QEbd")
|
||||
h1_elem = detail_panel.query_selector("h1") if detail_panel else None
|
||||
nome_empresa = h1_elem.inner_text().strip() if h1_elem else ""
|
||||
if nome_empresa.lower() in ('resultados', 'resultado', ''):
|
||||
title_elem = page.query_selector(".fontHeadlineLarge, .DUwif, div.qBF1Pd")
|
||||
nome_empresa = title_elem.inner_text().strip() if title_elem else ""
|
||||
|
||||
if nome_empresa and nome_empresa.lower() not in ('resultados', 'resultado'):
|
||||
detail_text = detail_panel.inner_text() if detail_panel else ""
|
||||
|
||||
telefone_raw = ""
|
||||
|
||||
Reference in New Issue
Block a user