Python - download file using GET form
<p>I am trying to write a  script that downloads a xlsx file and saves it to the computer. This file doesn't have a specific path and it gets generated after filling a <code>GET</code> form. There are two submit buttons. </p>

<p>The first one makes a list of results under the form (I can do it). 
The second one creates a xlsx file and asks where to save it.</p>

<pre><code>&lt;form action="/search" method="get" id="frm-detailedSearchForm"&gt;
</code></pre>

<p>...</p>

<pre><code>&lt;input type="text" name="publication_date[from]" class="date" tabindex="1" id="frm-detailedSearchForm-publication_date-from" data-nette-rules='[{"op":":filled","rules":[{"op":":pattern","msg":"NevalidnÃ­ formÃ¡t data (dd.mm.rrrr)","arg":"\\d{1,2}\\.\\d{1,2}.\\d{4}"}],"control":"publication_date[from]"}]'&gt;
</code></pre>

<p>...</p>

<pre><code>&lt;input type="submit" name="search" class="w-button btn ajax" tabindex="27" value="Search"&gt;
&lt;input type="submit" name="export" class="w-button btn" tabindex="28" value="Export"&gt;
&lt;input type="hidden" name="do" value="detailedSearchForm-submit"&gt;&lt;/form&gt;
</code></pre>

<hr>

<p>EDIT:
Solution was easy in the end (using mechanize lib):</p>

<pre><code>url = url + ?do=detailedSearchForm-submit&amp;export=Export
browser.retrieve(url, file.xlsx)
</code></pre>

<p>Thank you.</p>

<p>if I get you right you're trying to write a script that interacts with an existing website, fills a form, downloads a file and saves it, right?
you're not the one writing the website.</p>

<p>is so - I highly recommend using <a href="http://selenium-python.readthedocs.io/" rel="nofollow">selenium</a> to automate the task of filling the form <strong>on top of a real browser</strong>. it's a bit hard to start but much much more resilient.</p>

<p>while you theoretically could write a script that downloads the file from a url that fakes a form submission, this attitude is often times a source of troubles. if the site is over some level of complexity - the likelihood of this attitude to work is very low.</p>

python downloadfile