bundesAPI / handelsregister

308 stars 38 forks source link

Python packaging fails / PHP implementation desirable #29

Open wq9578 opened 2 months ago

wq9578 commented 2 months ago

On a current Mac, poetry installed via Homebrew fails:

$ poetry install

Command ['/opt/homebrew/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/bin/python3.12', '-I', '-W', 'ignore', '-c', 'import sys\n\nif hasattr(sys, "real_prefix"):\n    print(sys.real_prefix)\nelif hasattr(sys, "base_prefix"):\n    print(sys.base_prefix)\nelse:\n    print(sys.prefix)\n'] errored with the following return code -10

A PHP implementation would be desirable to obtain structured information (SI) as well as the current (AD) and chronological excerpt (CD) for a given legal entity. With the Laravel framework, either Laravel's HTTP client powered by Guzzle might be used, or Laravel Dusk using a Selenium compatible driver if JavaScript is required. Unfortunately, this seems to be the case.

Both a request with curl (curl -d "registerArt_input=VR" -d "registerNummer=304" -d "registergericht_input=D2601" https://www.handelsregister.de/rp_web/erweitertesuche.xhtml) as well as a request with Laravel's HTTP client (obtaining the cookie in a first request, then reusing this cookie requesting the extended search form) fails with the error message "session expired".

Test using PHP Pest:

use Illuminate\Support\Facades\Http;

it('makes a request at handelsregister.de',
    closure: function () {
        $response = Http::get('https://www.handelsregister.de');

        // https://stackoverflow.com/a/70330475
        $cookie_value = $response->cookies->getCookieByName('JSESSIONID')->getValue();

        dump($cookie_value);

        // Advanced search
        $response = Http::withCookies(['JSESSIONID' => $cookie_value],
            'www.handelsregister.de')->get('https://www.handelsregister.de/rp_web/welcome.xhtml#');

        dump($response);
    });

It's a shame that the German federal services don't offer a proper API. Also, a rate limit of 60 requests per hour is ridiculous for publicly available data.

amacado commented 22 hours ago

@wq9578 if you're interested, i have a working prototype implementation for the "api" using laravel dusk within laravel zero as a cli application to interact with the handelsregister website.

Arguments:
  language                                     Language which is used for interaction with `Handelsregister`. [default: "DE"]

Options:
      --state[=STATE]                          Select zero, one or more federal states to search in. If none are passed, the search will not be limited to a specific state. Valid codes are based on iso:code:3166:DE. (multiple values allowed)
      --keywords[=KEYWORDS]                    Search for company or keywords.
      --keywords-option[=KEYWORDS-OPTION]      Select an option how `keywords` are treated; One of (all|any|exact). [default: "any"]
      --keywords-match-similar                 If flag is set, similar matching keywords will be included in results.
      --subsidiary-office[=SUBSIDIARY-OFFICE]  Subsidiary / registered office.
      --include-deleted                        If flag is set, search results will also include deleted companies.
      --only-branches                          If flag is set, search only for branches in accordance with new law.
      --register-type[=REGISTER-TYPE]          Type of register (input value is language-dependent).
      --register-number[=REGISTER-NUMBER]      Company register number.
      --register-court[=REGISTER-COURT]        Register court (input value is language-dependent).
      --legal-status[=LEGAL-STATUS]            Company legal status (input value is language-dependent).
      --country[=COUNTRY]                      Country where the company is located (input value is language-dependent).
      --postal-code[=POSTAL-CODE]              Postal code where the company is located.
      --location[=LOCATION]                    Location/City where the company is located.
      --street[=STREET]                        Street where the company is located.
  -h, --help                                   Display help for the given command. When no command is given display help for the list command
  -q, --quiet                                  Do not output any message
  -V, --version                                Display this application version
      --ansi|--no-ansi                         Force (or disable --no-ansi) ANSI output
  -n, --no-interaction                         Do not ask any interactive question
      --env[=ENV]                              The environment the command should run under
  -v|vv|vvv, --verbose                         Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug