[Python] Imitate post request triggered by button on website in python requests

Discussão em 'Python' iniciado por Stack, Agosto 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm attempting to imitate the post request being triggered by the 'Download as CSV' button the webpage https://www.bundesanzeiger.de/pub/en/nlp?2. However I'm consistently returning an error webpage rather than the csv file.

    Inspecting the html for the button gives the following:

    <form method="post" action="https://www.bundesanzeiger.de/pub/en/nlp?2-2.-top~csv~form~panel-form" id="idf2"><div id="idf2_hf_0" hidden="" class="hidden-fields"></div>

    <a class="btn btn-green argus-A98" target="_blank" href="https://www.bundesanzeiger.de/pub/en/nlp?2--top~csv~form~panel-form-csv~resource~link" title="Download as CSV"><span>Download as CSV</span>&nbsp;&nbsp;<i class="fas fa-file-csv"></i></a>
    </form>


    I had interpreted this as the html request being sent to the 'action' url with the payload id='idf2', and wrote the following snipet:

    import requests

    url = 'https://www.bundesanzeiger.de/pub/en/nlp?2--top~csv~form~panel-form-csv~resource~link'
    payload = {'id': 'idf2'}

    r = requests.post(url, json=payload)
    r.content


    However this just returns a webpage saying that there's been an error. Is there something I'm missing from my request? I also tried supplying a 'User-Agent' in the headers, but this doesn't seem to work either.

    Continue reading...

Compartilhe esta Página