handelsregister

command line interface for handelsregister.de
git clone https://git.ce9e.org/handelsregister.git

commit
4661bf27b2d41dbe6f61d97b394e482e7477f952
parent
e3def90515a39ddfbc4fd5989cbff9a8094f2f22
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-12-07 14:56
parse_id

Diffstat

M handelsregister.py 17 +++++++++++++++--

1 files changed, 15 insertions, 2 deletions


diff --git a/handelsregister.py b/handelsregister.py

@@ -14,6 +14,19 @@ REGISTERS = {
   14    14 }
   15    15 
   16    16 
   -1    17 def parse_id(s):
   -1    18     parts = s.strip().split()
   -1    19     for i in range(len(parts) - 2, 0, -1):
   -1    20         reg = parts[i]
   -1    21         if reg in REGISTERS:
   -1    22             return {
   -1    23                 'court': ' '.join(parts[:i]),
   -1    24                 'reg': reg,
   -1    25                 'id': ' '.join(parts[i + 1:]),
   -1    26             }
   -1    27     raise ValueError(s)
   -1    28 
   -1    29 
   17    30 def fetch_view_state(session):
   18    31     r = session.get('https://www.handelsregister.de/rp_web/erweitertesuche/welcome.xhtml')
   19    32     r.raise_for_status()
@@ -48,7 +61,7 @@ def search(terms, register=''):
   48    61     for item in soup.select('[data-ri]'):
   49    62         yield {
   50    63             'title': item.select_one('.marginLeft20').text,
   51    -1             'id': item.select_one('.fontWeightBold').text.strip(),
   -1    64             **parse_id(item.select_one('.fontWeightBold').text),
   52    65         }
   53    66 
   54    67 
@@ -102,6 +115,6 @@ if __name__ == '__main__':
  102   115     if args.action == 'search':
  103   116         for item in search(args.terms):
  104   117             print(item['title'])
  105    -1             print('\t' + item['id'])
   -1   118             print('\t', item['court'], item['reg'], item['id'])
  106   119     else:
  107   120         print(get_xml(args.register, args.id))