0

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 GET form. There are two submit buttons.

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.

<form action="/search" method="get" id="frm-detailedSearchForm">
...

<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]"}]'>

...
<input type="submit" name="search" class="w-button btn ajax" tabindex="27" value="Search">
<input type="submit" name="export" class="w-button btn" tabindex="28" value="Export">
<input type="hidden" name="do" value="detailedSearchForm-submit"></form>
Zoe
  • 27,060
  • 21
  • 118
  • 148
  • 1
    You should always show us the python code you have developed so far. Have a look here to get started http://stackoverflow.com/a/1171409/640916 – djangonaut Sep 08 '16 at 08:07
  • I tryied many type of codes so it is hard to say which one is the best to start. browser = mechanize.Browser(factory=mechanize.RobustFactory()) browser.set_handle_robots(False) browser.open(url) browser.select_form(nr=1) browser.form["publication_date[from]"] = "01.09.2016" browser.form["publication_date[to]"] = "01.09.2016" This works for me, when I use browser.submit(). When I tryied to use browser.submit(nr=1) nothing happend. – Martina Karbusická Sep 08 '16 at 08:48

1 Answers1

0

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.

is so - I highly recommend using selenium to automate the task of filling the form on top of a real browser. it's a bit hard to start but much much more resilient.

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.

akiva
  • 2,677
  • 3
  • 31
  • 40
  • Exactly, I am not the one writing the website. I just need something that everyday download files pubslihed the day before (fill the publication_date[from] and dowload and save file to my computer). – Martina Karbusická Sep 08 '16 at 08:55
  • @MartinaKarbusická - if you find my answer useful - please feel free to accept it/upvote – akiva Sep 08 '16 at 10:42