0

I'm trying to download a few files using roboBrowser, URLLIB or any other python library, but I couldn't find a way to make it work.

Basically, I have a form which retrieves a .CSV file when is submitted, but I couldn't find any way to start this download.

I have submitted the form using RoboBrowser and URLLIB post but I couldn't reach the file

    Form = browser.get_form(action=re.compile(r'downloadForm'))
    Form ["d_screen_file"].value = "1"
    browser.submit_form(Form , submit=programForm['download'])

or

    action = browser.find('form', id='fx_form').get('action')
    requests.post(action)

There is another way to submit this form/make this requisition to engage this download?

  • it would be helpful if you could post the error message you are getting. You might not have permission to download the file from the site? – d_kennetz Aug 21 '18 at 17:48
  • Possible duplicate of [How do I download a file over HTTP using Python?](https://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python) – Darrick Herwehe Aug 21 '18 at 18:34

1 Answers1

0

I figure out how to make it work:

Using requests I do it a post with stream=True

f = session.post(FormRequest, data=search_data, stream=True)

After that, I create a CSV file to receive this data and use a for loop to parse the data using iter_content and write in the file

with open("file.csv", 'wb') as s: 
    for chunk in f.iter_content(chunk_size=1024): 
        s.write(chunk)