Deepsek V4
Erweiterte Schlüsselwörter:
python
Copy
'branche': ['branche', 'industrie', 'produkte', ...],
'umsatz': ['umsatz', 'jahresumsatz', 'ergebnis', ...]
Robustere Infobox-Erkennung:
python
Copy
class_=lambda c: any(kw in c.lower() for kw in ['infobox', 'vcard', 'unternehmen'])
Verbesserte Zellenverarbeitung:
Berücksichtigt Listen (<li>-Elemente)
Ignoriert verschachtelte Tabellen
Sucht in allen relevanten Zellen (<th> und <td>)
Präzise Umsatzextraktion:
python
Copy
r'(\d{1,3}(?:[.,]\d{3})*(?:[.,]\d{2})?)\s*(?:Mio\.?|Millionen|...)\s*(?:€|Euro|EUR)'
This commit is contained in:
@@ -12,7 +12,7 @@ import csv
|
||||
|
||||
# ==================== KONFIGURATION ====================
|
||||
class Config:
|
||||
VERSION = "1.1.0"
|
||||
VERSION = "1.1.1"
|
||||
LANG = "de"
|
||||
CREDENTIALS_FILE = "service_account.json"
|
||||
SHEET_URL = "https://docs.google.com/spreadsheets/d/1u_gHr9JUfmV1-iviRzbSe3575QEp7KLhK5jFV_gJcgo"
|
||||
@@ -185,26 +185,64 @@ class WikipediaScraper:
|
||||
'url': page_url
|
||||
}
|
||||
|
||||
[file name]: claude.py
|
||||
[file content begin]
|
||||
# ==================== WIKIPEDIA SCRAPER ====================
|
||||
class WikipediaScraper:
|
||||
# ... (vorheriger Code bleibt unverändert)
|
||||
|
||||
def _extract_infobox_value(self, soup, target):
|
||||
"""Extrahiert spezifischen Wert aus der Infobox"""
|
||||
infobox = soup.find('table', class_=lambda c: c and 'infobox' in c.lower())
|
||||
"""Extrahiert spezifischen Wert aus der Infobox mit erweiterten Suchmustern"""
|
||||
# Erweiterte Infobox-Erkennung
|
||||
infobox = soup.find('table', class_=lambda c: c and any(
|
||||
kw in c.lower() for kw in ['infobox', 'vcard', 'unternehmen']
|
||||
))
|
||||
|
||||
if not infobox:
|
||||
return "k.A."
|
||||
|
||||
# Definiere Keywords für verschiedene Targets
|
||||
|
||||
keywords = {
|
||||
'branche': ['branche', 'tätigkeitsfeld', 'geschäftsfeld', 'sektor'],
|
||||
'umsatz': ['umsatz', 'jahresumsatz', 'konzernumsatz', 'umsatzerlöse']
|
||||
'branche': [
|
||||
'branche', 'industrie', 'tätigkeitsfeld', 'geschäftsfeld',
|
||||
'sektor', 'produkte', 'leistungen', 'geschäftsbereich'
|
||||
],
|
||||
'umsatz': [
|
||||
'umsatz', 'jahresumsatz', 'umsatzerlöse', 'gesamtumsatz',
|
||||
'konzernumsatz', 'umsatzentwicklung', 'ergebnis'
|
||||
]
|
||||
}.get(target, [])
|
||||
|
||||
# Durchsuche Infobox-Zeilen
|
||||
|
||||
# Durchsuche alle Zeilen und Zellen
|
||||
value = "k.A."
|
||||
for row in infobox.find_all('tr'):
|
||||
header = row.find('th')
|
||||
if header and any(kw in clean_text(header).lower() for kw in keywords):
|
||||
value = row.find('td')
|
||||
return clean_text(value) if value else "k.A."
|
||||
|
||||
# Erweiterte Header-Erkennung in th/td mit colspan
|
||||
header_cells = row.find_all(['th', 'td'], attrs={'colspan': False})
|
||||
for header in header_cells:
|
||||
header_text = clean_text(header.get_text()).lower()
|
||||
|
||||
if any(kw in header_text for kw in keywords):
|
||||
# Hole nächste Zelle, ignoriere verschachtelte Tabellen
|
||||
value_cell = header.find_next_sibling(['td', 'th'])
|
||||
if value_cell:
|
||||
# Verarbeite Listen und mehrzeilige Inhalte
|
||||
list_items = value_cell.find_all('li')
|
||||
if list_items:
|
||||
value = ', '.join(clean_text(li.get_text()) for li in list_items)
|
||||
else:
|
||||
value = clean_text(value_cell.get_text())
|
||||
|
||||
# Extrahiere numerische Umsatzwerte mit Regex
|
||||
if target == 'umsatz':
|
||||
match = re.search(
|
||||
r'(\d{1,3}(?:[.,]\d{3})*(?:[.,]\d{2})?)\s*(?:Mio\.?|Millionen|Mrd\.?|Milliarden)?\s*(?:€|Euro|EUR)',
|
||||
value
|
||||
)
|
||||
if match:
|
||||
value = match.group(1).replace('.', '').replace(',', '.')
|
||||
return value
|
||||
|
||||
return "k.A."
|
||||
[file content end]
|
||||
|
||||
# ==================== DATA PROCESSOR ====================
|
||||
class DataProcessor:
|
||||
|
||||
Reference in New Issue
Block a user