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_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()
|
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)
|
# 1. Nome da Empresa (priorizar aria-label do card ou h1 dentro do detail_panel)
|
||||||
h1_elem = page.query_selector("h1")
|
nome_empresa = (card.get_attribute("aria-label") or "").strip()
|
||||||
nome_empresa = ""
|
if nome_empresa.lower() in ('resultados', 'resultado', ''):
|
||||||
if h1_elem:
|
nome_empresa = ""
|
||||||
nome_empresa = h1_elem.inner_text().strip()
|
|
||||||
if not nome_empresa:
|
if not nome_empresa and detail_panel:
|
||||||
nome_empresa = (card.get_attribute("aria-label") or "").strip()
|
h1_elem = detail_panel.query_selector("h1")
|
||||||
if not nome_empresa:
|
if h1_elem:
|
||||||
lines = [l.strip() for l in card.inner_text().split('\n') if l.strip()]
|
h_txt = h1_elem.inner_text().strip()
|
||||||
nome_empresa = lines[0] if lines else ""
|
if h_txt and h_txt.lower() not in ('resultados', 'resultado'):
|
||||||
|
nome_empresa = h_txt
|
||||||
|
|
||||||
if not nome_empresa:
|
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
|
continue
|
||||||
|
|
||||||
# 2. Telefone detalhado
|
# 2. Telefone detalhado
|
||||||
@@ -182,10 +190,14 @@ class ScraperService:
|
|||||||
else:
|
else:
|
||||||
# Se for resultado único direto
|
# Se for resultado único direto
|
||||||
try:
|
try:
|
||||||
h1_elem = page.query_selector("h1")
|
detail_panel = page.query_selector("div[role='main']") or page.query_selector("div.m6QEbd")
|
||||||
if h1_elem:
|
h1_elem = detail_panel.query_selector("h1") if detail_panel else None
|
||||||
nome_empresa = h1_elem.inner_text().strip()
|
nome_empresa = h1_elem.inner_text().strip() if h1_elem else ""
|
||||||
detail_panel = page.query_selector("div[role='main']") or page.query_selector("div.m6QEbd")
|
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 ""
|
detail_text = detail_panel.inner_text() if detail_panel else ""
|
||||||
|
|
||||||
telefone_raw = ""
|
telefone_raw = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user