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 ====================
|
# ==================== KONFIGURATION ====================
|
||||||
class Config:
|
class Config:
|
||||||
VERSION = "1.1.0"
|
VERSION = "1.1.1"
|
||||||
LANG = "de"
|
LANG = "de"
|
||||||
CREDENTIALS_FILE = "service_account.json"
|
CREDENTIALS_FILE = "service_account.json"
|
||||||
SHEET_URL = "https://docs.google.com/spreadsheets/d/1u_gHr9JUfmV1-iviRzbSe3575QEp7KLhK5jFV_gJcgo"
|
SHEET_URL = "https://docs.google.com/spreadsheets/d/1u_gHr9JUfmV1-iviRzbSe3575QEp7KLhK5jFV_gJcgo"
|
||||||
@@ -185,26 +185,64 @@ class WikipediaScraper:
|
|||||||
'url': page_url
|
'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):
|
def _extract_infobox_value(self, soup, target):
|
||||||
"""Extrahiert spezifischen Wert aus der Infobox"""
|
"""Extrahiert spezifischen Wert aus der Infobox mit erweiterten Suchmustern"""
|
||||||
infobox = soup.find('table', class_=lambda c: c and 'infobox' in c.lower())
|
# 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:
|
if not infobox:
|
||||||
return "k.A."
|
return "k.A."
|
||||||
|
|
||||||
# Definiere Keywords für verschiedene Targets
|
|
||||||
keywords = {
|
keywords = {
|
||||||
'branche': ['branche', 'tätigkeitsfeld', 'geschäftsfeld', 'sektor'],
|
'branche': [
|
||||||
'umsatz': ['umsatz', 'jahresumsatz', 'konzernumsatz', 'umsatzerlöse']
|
'branche', 'industrie', 'tätigkeitsfeld', 'geschäftsfeld',
|
||||||
|
'sektor', 'produkte', 'leistungen', 'geschäftsbereich'
|
||||||
|
],
|
||||||
|
'umsatz': [
|
||||||
|
'umsatz', 'jahresumsatz', 'umsatzerlöse', 'gesamtumsatz',
|
||||||
|
'konzernumsatz', 'umsatzentwicklung', 'ergebnis'
|
||||||
|
]
|
||||||
}.get(target, [])
|
}.get(target, [])
|
||||||
|
|
||||||
# Durchsuche Infobox-Zeilen
|
# Durchsuche alle Zeilen und Zellen
|
||||||
|
value = "k.A."
|
||||||
for row in infobox.find_all('tr'):
|
for row in infobox.find_all('tr'):
|
||||||
header = row.find('th')
|
# Erweiterte Header-Erkennung in th/td mit colspan
|
||||||
if header and any(kw in clean_text(header).lower() for kw in keywords):
|
header_cells = row.find_all(['th', 'td'], attrs={'colspan': False})
|
||||||
value = row.find('td')
|
for header in header_cells:
|
||||||
return clean_text(value) if value else "k.A."
|
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."
|
return "k.A."
|
||||||
|
[file content end]
|
||||||
|
|
||||||
# ==================== DATA PROCESSOR ====================
|
# ==================== DATA PROCESSOR ====================
|
||||||
class DataProcessor:
|
class DataProcessor:
|
||||||
|
|||||||
Reference in New Issue
Block a user