DEV Community

Bachir Djoukbala
Bachir Djoukbala

Posted on

How to extract German company data (register number, VAT ID, managing director) from a website's Impressum with Python

Every commercial website in Germany, Austria and Switzerland has to publish an Impressum (legal notice). It is the single best free source for B2B lead and KYB data on a company you only know by its domain: legal name and form, registered address, commercial register number and court (HRB/HRA), VAT ID (USt-IdNr), managing directors and a contact email.

This post shows a working DIY approach, where it breaks, and what to do when you have a list of thousands of domains.

Step 1: find the Impressum page

There is no standard URL, so look for a footer link first and fall back to common paths.

import re, httpx
from urllib.parse import urljoin

HEADERS = {"User-Agent": "Mozilla/5.0 (compatible; lead-research/1.0)"}
PATHS = ["/impressum", "/impressum/", "/impressum.html", "/imprint", "/kontakt/impressum"]

def to_text(html: str) -> str:
    html = re.sub(r"(?is)<(script|style).*?</\1>", " ", html)
    html = re.sub(r"(?i)<br\s*/?>|</p>|</div>|</li>|</h\d>", "\n", html)
    text = re.sub(r"<[^>]+>", " ", html)
    text = text.replace("&nbsp;", " ").replace("&amp;", "&")
    return re.sub(r"[ \t\xa0]+", " ", re.sub(r"\n\s*\n+", "\n", text))

def find_impressum(client, domain):
    base = f"https://{domain}"
    home = client.get(base)
    m = re.search(r'href="([^"]*(?:impressum|imprint)[^"]*)"', home.text, re.I)
    candidates = [urljoin(str(home.url), m.group(1))] if m else []
    candidates += [urljoin(str(home.url), p) for p in PATHS]
    for url in candidates:
        r = client.get(url)
        if r.status_code == 200 and re.search(r"impressum|imprint", r.text, re.I):
            return url, to_text(r.text)
    return None, ""

def parse(text):
    court = re.search(r"(?:Amtsgericht|Registergericht)[:\s]+([A-ZÄÖÜ][\wäöüß\-]+(?: (?!HR[AB])[A-ZÄÖÜ][\wäöüß\-]+)?)", text)
    return {
        "register": re.findall(r"HR[AB]\s?\d{3,6}(?:\s?[A-Z]{1,2})?", text)[:2],
        "court": court.group(1) if court else None,
        "vat_id": re.findall(r"DE\s?\d{3}\s?\d{3}\s?\d{3}", text)[:2],
        "directors": [d.strip() for d in re.findall(
            r"(?:Geschäftsführer(?:in)?|Vorstand|Geschäftsführung|Managing Directors?)[:\s]+([^\n]{3,90})", text)
            if re.search(r"[A-Z][a-zäöüß]+ [A-Z][a-zäöüß]+", d)][:3],
        "emails": sorted(set(re.findall(r"[\w.+-]+@[\w-]+\.[\w.]*\w", text)))[:3],
    }
Enter fullscreen mode Exit fullscreen mode

Step 2: run it

import httpx
with httpx.Client(follow_redirects=True, timeout=20, headers=HEADERS) as c:
    url, text = find_impressum(c, "www.heise.de")
    print(url, parse(text))
Enter fullscreen mode Exit fullscreen mode

Output when I ran it (Nov 2026):

https://www.heise.de/impressum.html
{'register': ['HRB 60405', 'HRA 26709'], 'court': 'Hannover', 'vat_id': ['DE 813 501 887'], 'directors': [], 'emails': ['recht@heise.de', 'webmaster@heise.de']}
Enter fullscreen mode Exit fullscreen mode

and for zalando.de: register HRB 158855 B, court Charlottenburg Berlin, VAT IDs DE862107002 and DE 260543043, plus the board names.

Where the regex approach breaks

I ran this on a handful of well known sites and these are the problems you will hit:

  • Several legal entities on one page (heise lists an HRB and an HRA, hellofresh two registers, otto two HRBs). You need to decide which one is the operating company.
  • The court is written many ways ("Amtsgericht Hannover", "Registergericht: Charlottenburg Berlin", or just next to the number), and a naive regex picks up the next word, like "HRB".
  • Directors written as free text: "Robert Gentz & David Schröder (beide Co-Vorstandsvorsitzende), Dr. Astrid Arndt, ...", or inside tables, or after "vertreten durch".
  • Austria uses a Firmenbuchnummer (FN 123456a) and ATU VAT IDs, Switzerland uses CHE-123.456.789 UIDs, so the patterns above need extending.
  • All-caps surnames, job titles mixed into the name field, and pages that only render in JavaScript.

None of this is hard, but it is the long tail that eats the time. Plan on a day of tuning for decent accuracy, then ongoing fixes.

For lists: a hosted version

Disclosure: I built an Apify actor that handles these cases, Impressum Scraper DE/AT/CH. You give it a list of domains and it returns one clean record per company: name, legal form, address, register number and court (DE HRB/HRA, AT FN, CH UID), VAT ID, directors, emails, phones and social links, as JSON or CSV. It is pay per use, and the free Apify credit is enough to test it on your own list.

If you would rather keep it in-house, the code above is a reasonable start. Two notes either way:

  • Impressum data is public, but names and emails of people are personal data under GDPR. Check your legal basis before cold outreach.
  • Be polite: a couple of requests per domain, timeouts, and a descriptive user agent.

Questions or a field you want added? Leave a comment.

Top comments (0)