Wikipedia Bugfix
Wikipedia-Suche ist vollständig implementiert: Suchbegriffe: vollständiger Firmenname, erste zwei Wörter, Domainname wikipedia.search() liefert bis zu 3 Treffer Titelvergleich verhindert falsche Zuordnung HTML der Seite wird geladen Infobox mit infobox oder infobox vcard wird geprüft Branche wird aus <th>Branche</th> extrahiert Umsatz wird aus „Umsatz“ extrahiert, falls „Mio“ enthalten, auf Zahl bereinigt (z. B. „159 Mio. €“ → 159) ✅ Wikipedia-Branche und Umsatz werden korrekt in wiki_branche bzw. umsatz gespeichert. ✅ Diese Werte werden beim Schreiben bevorzugt: python Copy Edit wiki_final = wiki_branche if wiki_branche != "k.A." else wiki umsatz_final = umsatz if umsatz != "k.A." else umsatz_chat ✅ Es werden alle Spalten korrekt im Sheet geschrieben (G bis P).
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import csv
|
import csv
|
||||||
|
import re
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import gspread
|
import gspread
|
||||||
import openai
|
import openai
|
||||||
@@ -101,8 +102,7 @@ def get_wikipedia_data(name, website_hint=""):
|
|||||||
if website_hint:
|
if website_hint:
|
||||||
parts = website_hint.replace("https://", "").replace("http://", "").split(".")
|
parts = website_hint.replace("https://", "").replace("http://", "").split(".")
|
||||||
if len(parts) > 1:
|
if len(parts) > 1:
|
||||||
begriffe.append(parts[0]) # z. B. "heimbach" aus "www.heimbach.com"
|
begriffe.append(parts[0])
|
||||||
|
|
||||||
for suchbegriff in begriffe:
|
for suchbegriff in begriffe:
|
||||||
results = wikipedia.search(suchbegriff, results=3)
|
results = wikipedia.search(suchbegriff, results=3)
|
||||||
for title in results:
|
for title in results:
|
||||||
@@ -113,7 +113,7 @@ def get_wikipedia_data(name, website_hint=""):
|
|||||||
url = page.url
|
url = page.url
|
||||||
html = requests.get(url).text
|
html = requests.get(url).text
|
||||||
soup = BeautifulSoup(html, 'html.parser')
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
infobox = soup.find("table", {"class": "infobox"})
|
infobox = soup.find("table", class_=["infobox", "infobox vcard"])
|
||||||
branche = umsatz = ""
|
branche = umsatz = ""
|
||||||
if infobox:
|
if infobox:
|
||||||
for row in infobox.find_all("tr"):
|
for row in infobox.find_all("tr"):
|
||||||
@@ -123,7 +123,11 @@ def get_wikipedia_data(name, website_hint=""):
|
|||||||
if "Branche" in th.text:
|
if "Branche" in th.text:
|
||||||
branche = td.text.strip()
|
branche = td.text.strip()
|
||||||
if "Umsatz" in th.text:
|
if "Umsatz" in th.text:
|
||||||
umsatz = td.text.strip()
|
umsatz_raw = td.text.strip()
|
||||||
|
if "Mio" in umsatz_raw:
|
||||||
|
match = re.search(r"(\d+[,.]?\d*)", umsatz_raw)
|
||||||
|
if match:
|
||||||
|
umsatz = match.group(1).replace(",", ".")
|
||||||
if not branche:
|
if not branche:
|
||||||
cats = page.categories
|
cats = page.categories
|
||||||
branche = cats[0] if cats else "k.A."
|
branche = cats[0] if cats else "k.A."
|
||||||
|
|||||||
Reference in New Issue
Block a user